내부 다수의 서버에 사설IP를 할당하고 외부인터넷과 연결되는 1대의 서버를 통해 사설대역에 인터넷을 가능하게 하기위한 pNAT 구성예시

1. VMWARE Network 구성
- vSwitch0 -> Port groups 설정에서 "VM Network" 사내 내부IP로 구성 192.168.240.0/21 대역
- Internal-vSwitch0 -> ESXi 서버끼리 연결된 VM 내부대역 마찬가지로 "internal-VMnetwork"으로 구성 10.10.10.0/24 대역으로 설정
2. pNAT용서버구성
– Ubuntu 22.04 설치
Ubuntu 22.04.3 server OS 설치.
VM Network/internal-VMnetwork 2개의 vNIC 생성
사용 패키지 설치 openssh, net-tools 등
– DHCP 서버 구성
(참조 :https://makepluscode.tistory.com/165
https://www.linux.co.kr/bbs/board.php?bo_table=lecture&wr_id=2089)
dhcp 서버 설치 : sudo apt install isc-dhcp-server
dhcp 설정수정 : sudo vi /etc/dhcp/dhcpd.conf
option domain-name "rn-test.local";
option domain-name-servers 168.126.63.1, 8.8.8.8;
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.101 10.10.10.200;
option domain-name-servers 168.126.63.1, 8.8.8.8;
option routers 10.10.10.1;
}
dhcp 설정수정 : sudo vi /etc/default/isc-dhcp-server
INTERFACESv4="ens192"
INTERFACESv6="ens192"
isc-dhcp-server 시작 : sudo systemctl start isc-dhcp-server
isc-dhcp-server 상태확인 : sudo systemctl status isc-dhcp-server
Client에서 DHCP 주소 수신 확인 :
Client VM에서 IPv4 구성 DHCP 자동구성확인, onboot=yes 또는 Automatically
connect 확인 후, network 재시작 후, IP address 10.10.10.101 이후 자동할당 확인
netstat -rn 명령어시 10.10.10.1(pNAT Server NIC) GW로 구성확인
/etc/resolv.conf 파일에 dhcp server 설정에 지정된 dns 구성 확인
– pNAT 구성
참조링크 : https://linuxhint.com/configure-nat-on-ubuntu/
https://recordnb.tistory.com/7abb7c259abb7c259
iptables persistent 설치 : sudo apt install iptables-persistent
부팅시 iptable ipv4 시작 : sudo systemctl enable iptables.service
시작 및 확인 : sudo systemctl start iptables.service
systemctl status iptables.service
load 가능한 kernel module 확인 : find /lib/modules/$(uname -r) -type f -name '*.ko' |grep iptable
/lib/modules/5.15.0-105-generic/kernel/net/ipv4/netfilter/iptable_nat.ko
iptable_nat 모듈 커널에 로드 :
현재 로드되어있는 모듈확인 : lsmod |grep table
nf_tables 266240 0
nfnetlink 20480 1 nf_tables
ip_tables 32768 0
x_tables 53248 1 ip_tables
iptable_nat 모듈 로드 : sudo modprobe iptable_nat
확인 : lsmod |grep table
iptable_nat 16384 0
nf_nat 49152 1 iptable_nat
nf_tables 266240 0
nfnetlink 20480 1 nf_tables
ip_tables 32768 1 iptable_nat
x_tables 53248 2 ip_tables,iptable_nat
리부팅시 해당 모듈 자동으로 로드 : sudo vi /etc/modules-load.d/modules.conf
options iptable_nat
net.ipv4.ip_forward = 1 적용 : sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1
$ sudo sysctl -p
iptables 값 적용 : sudo iptables -t nat -A POSTROUTING -j MASQUERADE
sudo iptables -A FORWARD -i ens192 -j ACCEPT
확인 : sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
iptables config 저장, 리붓시 사용 : sudo sh -c "iptables-save > /etc/iptables/rules.v4"
3. client 확인
ping www.google.co.kr
PING www.google.co.kr (172.217.25.163) 56(84) bytes of data.
64 bytes from syd09s13-in-f3.1e100.net (172.217.25.163): icmp_seq=1 ttl=106 time=83.9 ms
64 bytes from syd09s13-in-f3.1e100.net (172.217.25.163): icmp_seq=2 ttl=106 time=84.1 ms
[dshan@testvm01 ~]$ curl ifconfig.me
211.168.184.130