1. Private vs Public IP (IPv4)
โถ Networking has two sorts of IPs. IPv4 and IPv6:
- IPv4 : 1.160.10.240
- IPv6: 3ffe: 1900:4545:3:200:f8ff:fe21:67cf
โถ AWS supports IPv4 and IPv6 both
โถ IPv4 is still the most common format used online.
โถ IPv6 is newer and solves problems for the Internet of Things (IoT).
โถ IPv4 allows for 3.7 billion different addresses in the public space.
โถ IPv4: [0-255].[0-255].[0-255]. [0-255].
2. Private vs Public IP (IPv4) Example
โถ every computer can talk to one another and talk to other server over internet
- when you have public IP youโre accessible over the internet.
- when you have private IP youโre only accessible within your private network.
์ฌ์ค IP๋ ์ง์ ์ธํฐ๋ท์ ์ฐ๊ฒฐ๋ ์ ์๋ค. ํ์ง๋ง NAT(Network Address Translation)๋ผ๋ ๊ธฐ์ ์ ์ฌ์ฉํ๋ฉด, ์ฌ์ค ๋คํธ์ํฌ์ ์๋ ์ฅ์น๋ ์ธํฐ๋ท๊ณผ ํต์ ํ ์ ์๋ค. ์ด NAT ์ฅ์น์ ํ๋ก์ ์ญํ ์ ํ ์ธํฐ๋ท ๊ฒ์ดํธ ์จ์ด๋ฅผ ํตํด ์ธํฐ๋ท์ ์ฐ๊ฒฐ๋๋ค.
์๋ฅผ ๋ค์ด, ์ง์์ ๊ณต์ ๊ธฐ๋ฅผ ์ฌ์ฉํ ๋, ๋ด ์ปดํจํฐ๋ ์ค๋งํธํฐ์ ์ฌ์ค IP(์: 192.168.x.x)๋ฅผ ๊ฐ์ง์ง๋ง, ๊ณต์ ๊ธฐ๋ ๊ณต์ธ IP๋ฅผ ๊ฐ๊ณ ์๋ค. ๋ด๊ฐ ์ธํฐ๋ท์ ์ ์ํ๋ฉด, ๊ณต์ ๊ธฐ๊ฐ ๋ด ์ฌ์ค IP๋ฅผ ๊ณต์ธ IP๋ก ๋ณํํด์ ์ธ๋ถ ์๋ฒ์ ํต์ ํ๋๋ก ํด ์ค๋ค. ๋ฐ๋๋ก, ์ธ๋ถ ์๋ฒ์์ ์๋ต์ด ์ค๋ฉด ๊ณต์ ๊ธฐ๊ฐ ๋ค์ ๋ด ์ฌ์ค IP๋ก ๋ณํํด์ ๋ด ์ฅ์น๋ก ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ์์ด๋ค.
์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ค ๋คํธ์ํฌ ๋ด๋ถ ์ฅ์น๋ ์ง์ ์ธํฐ๋ท์ ๋
ธ์ถ๋์ง ์๊ณ ๋ ์ธํฐ๋ท์ ์ฌ์ฉํ ์ ์๋ค. ์๋ฒ๋ ๋ง์ฐฌ๊ฐ์ง๋ก, ๋ง์ฝ ์ฌ์ค IP๋ฅผ ๊ฐ์ง ์๋ฒ๋ฅผ ์ธ๋ถ์์ ์ ๊ทผ ๊ฐ๋ฅํ๊ฒ ๋ง๋ค๊ณ ์ถ๋ค๋ฉด, ํฌํธ ํฌ์๋ฉ์ด๋ VPN ๊ฐ์ ๋ฐฉ๋ฒ์ ์ด์ฉํด์ผ ํ๋ค.
3. Private vs Public IP (IPv4) Fundamental Differences
2-1. Public IP:
โถ Public IP means the machine can be identified on the internet (WWW)
โถ Must be unique across the whole web (not two machines can have the same public IP).
โถ Can be ego-located easily
2-2. Private IP:
โถ Private IP means the machine can only be identified on a private network only
โถ The IP must be unique across private network.
โถ BUT two different private networks (two companies) can have the same IPs.
โถ Machines connect to WWW using a NAT + internet gateway (a proxy)
โถ Only a specified range of IPs can be used as private IP.
4. Elastic IPs
โถ When you stop and then start an EC2 instance, it can charge its public IP.
โถ If you need to have a fixed public IP for your instance, you need an Elastic IP.
โถ An Elastic IP is a public IPv4 you own as long as you don't delete it.
โถ You can attach it to one instance at a time.
โถ With an Elastic IP address, you can mask the failure of an instance or software by rapidly remapping the address to another instance in your account. (but its quite rare to use this way.)
โถ Because You can only have 5 Elastic IP in your account (you can ask AWS to increase that).
โญ Overall, try to avoid using Elastic IP:
- They often reflect poor architectural decisions
- Instead, use a random public IP and register a DNS name to it.
- Because much more control and expansion for us
- Or, as use a Load Balancer and don't use a public IP which is the best pattern you can have for AWS
5. Private vs Public IP (IPv4) in AWS EC2 (Hands On)
โถ By default, your EC2 machine comes with:
- A private IP for the internal AWS Network
- A public IP, for the WWW.
โถ When we are doing SSH into our EC2 machines:
- We can't use a private IP, because we are not in the same network.
- We only can use the public IP if you don't have VPN.
โถ If your machine is stopped and then started, the public IP can change.
6. ์ค์ต
6-1. use SSH with public IP address
ssh -i "your-key.pem" ec2-user@your-ec2-public-ip
Try using public ip
ssh -i .\EC2Tutorial.pem ec2-user@54.66.147.18
Try using public ip -> warning
ssh -i .\EC2Tutorial.pem ec2-user@172.31.7.68
์? ์ฌ์ค IPv4๋ ์ฌ์ค๋ง์ ์ํ๋ค. ์ง๊ธ์ AWS ์ฌ์ค๋ง์ ์ฐ๊ฒฐ๋์ด ์์ง ์๊ธฐ ๋๋ฌธ์ ์ธํฐ๋ท์ ํตํด์๋ง AWS์ ์ฐ๊ฒฐ ๊ฐ๋ฅํ๋ค. ๊ณต์ฉ IP๋ฅผ ์ฌ์ฉํด์ผ๋ง ๊ณต์ฉ๋ง์์ AWS์ ์ก์ธ์ค ํ ์ ์๋ค. ๊ณต์ฉ๋ง์ ์ธํฐ๋ท์ด ๋๋ค.
6-2. Stop an Instance and restart it
์ธ์คํด์ค๋ฅผ ์ฌ์์ํ๋ฉด ๊ณต์ฉ IP์ฃผ์๋ง ๋ฐ๋ ๊ฒ์ ํ์ธ ํด ๋ณผ ์ ์๋ค.
์ด์ ๊ณต์ฉIP๋ก SSH ์ฌ์ ์์ ์๋ํ๋ฉด ์ ์์ด ๋์ง ์๋๋ค.
๋ฐ๋ ๊ณต์ฉIP๋ก SSH ์ฌ์ ์์ ์๋ํ๋ฉด ์ ์์ด ์ ๋๋ค.
6-3. Elastic IP ์ค์ ๋ฒ (Associate Elastic IP address)
์ธ์คํด์ค๋ฅผ ์ค์งํ๊ณ ์ถ์๋ฐ ๊ณต์ฉ IP ๊ฐ ๋ฐ๋๋ ๊ฑด ์ํ์ง ์์ ๋ ์ฌ์ฉํ๋ ๊ฒ์ด Elastic IP (ํ๋ ฅ์ IP) ์ด๋ค.
Elastic IP ์ค์ ๋ฒ
AWS ์ฝ์ โ EC2 โ Elastic IPs โ Allocate Elastic IP โ ์์ฑ๋ IP ์ ํ โ Associate Elastic IP โ ๋์ ์ธ์คํด์ค ์ ํ โ Associate ๐
๋ค์ Instance ํญ์ผ๋ก ๋์๊ฐ ๋ณด๋ฉด ๊ธฐ์กด์ ๊ณต์ฉ IPv4 ์ฃผ์๋ ๋์ผํ์ง๋ง, Elastic IP Address ํ๋์ ๊ณต์ฉ ์ฃผ์์ธ ํ๋ ฅ์ IP์ฃผ์๊ฐ ํ์๋๋ค. (๋ด ๊ฒฝ์ฐ, ํ ๋ฒ ์ธ์คํด์ค๋ฅผ ์ค์งํ๊ณ ์ฌ์์ ํ๊ธฐ ๋๋ฌธ์ ์คํฌ๋ฆฐ์ท์์๋ ์๋ก์ด ๊ณต์ฉ IP์ฃผ์๊ฐ ํ ๋น๋จ)
ํด๋น Elastic IP ์ฃผ์๋ฅผ ํด๋ฆญํ๋ฉด EC2์ Elastic IP ์ฝ์๋ก ๋ฐ๋ก ์ด๋ํ๋ฉฐ ์ถ๊ฐ์ ์ธ ์ ๋ณด๋ฅผ ์ป์ ์ ์๋ค.
์ด์ Elastic IP ์ฃผ์๋ก SSH ๋ฅผ ์๋ํ๋ฉด ์ ์ฐ๊ฒฐ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
โญ ๊ทธ๋ฆฌ๊ณ ์ธ์คํด์ค๋ฅผ ์ค์งํด๋ ๊ณต์ฉ IP ์ฃผ์๊ฐ ๊ทธ๋๋ก ๋จ์ ์๋ ๊ฒ์ ๋์๋ณด๋์์ ํ์ธ ํ ์ ์๋ค.
โญ ์ธ์คํด์ค๋ฅผ ์ฌ์์ ํด๋ Elastic IP ์ฃผ์๋ ์ฌ์ ํ ๊ทธ๋๋ก ์ฐ๊ฒฐ๋์ด ์๊ณ ๊ณต์ฉ IP ์ฃผ์๋ ๋ณ๊ฒฝ๋์ง ์๋๋ค.
6-4. Elastic IP ํด์ ํ๋ ๋ฒ (Diassociate Elastic IP address)
AWS ์ฝ์ โ EC2 โ Elastic IPs โ IP ์ ํ โ Disassociate Elastic IP โ ํ์ธ ํ Disassociate โ Release Elastic IP address ๐
โญ Release Elastic IP address ๊น์ง ์๋ฃํด์ผ ์๊ธ์ด ๋ถ๊ณผ๋์ง ์์.
โญ AWS ์๊ธ ๊ณ์ฐ๊ธฐ
https://aws.amazon.com/ko/vpc/pricing/
AWS ์๊ธ ๊ณ์ฐ๊ธฐ โ ํผ๋ธ๋ฆญ IPv4 ์ฃผ์ ํญ
โญ AWS์์๋ ๊ณต์ฉ IPv4๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ์ฌ์ฉํ์ง ์๊ฑฐ๋ ์ฌ๋ถ์ ์๊ด ์์ด, ๊ณต์ฉ IPv4์ด๋ ํ๋ ฅ์ IPv4์ด๋ ๊ด๊ณ ์์ด ๋ชจ๋ IPv4 ์๋ ์๊ฐ๋น $0.005 ์๊ธ์ด ๋ถ๊ณผ๋๋ค.
โญ ํ์ฌ(2025.02.02) ํ์จ์ ๋ฐ์ํด์ ์ํ๋ก ๊ณ์ฐ ํด ๋ณด๋ฉด, ํ๋์ IPv4 ์ฃผ์๋ฅผ ํ ๋ฌ ๋์ ํ ๋น๋ฐ์์ ์ฌ์ฉํ๋ค๊ณ ๊ฐ์ ํด ๋ณผ ๋, ์๊ฐ ๋น 7.29์, ํ๋ฃจ(24์๊ฐ) 175์์ด ๊ณผ๊ธ๋๋ค. ํ๋ฌ๋ก ๊ณ์ฐ ํด ๋ณด๋ฉด 3.6 ๋ฌ๋ฌ์ธ 5,249์์ด ๋ถ๊ณผ๋๋ค.
โญ ๊ฒฐ๋ก ์ ๋ญ๋ค? ์ธ์คํด์ค์ ํ๋ ฅ์ IPS๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค๋ฉด ํด๋น ๋น์ฉ์ ์ง๋ถํ์ง ์๋๋ก ๋ฐ๋์ ์ข
๋ฃํด์ผ ํ๋ค๋ ๊ฒ์ด๋ค.
โญ AWS ์์๋ ๊ณ์ ๋ง๋ค ๋งค์ 750 ์๊ฐ์ ๋ฌด๋ฃ ๊ณต์ฉ IPv4 ์ฃผ์๊ฐ ์ ๊ณต๋๋ค. ๋ฐ๋ผ์ EC2 ์ธ์คํด์ค๋ฅผ ์ฐ์ต์ฉ์ผ๋ก ์์ฑํ๋ ๊ฒฝ์ฐ IPv4์ ์ 750 ์๊ฐ์ ์ด๊ณผํ์ง ์๋๋ก ์ค์ต์ด ๋๋๋ฉด ํด๋น ์ธ์คํด์ค๋ฅผ ๋ฐ๋์ ์ข
๋ฃํ๋๋ก ํ์.