Article title: a simple practice of NAT using IPtables in RHLE5 operating system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Implementation: The Linux host performs routing to achieve shared internet access for the subnet. Two IP addresses, one public IP address (22.33.44.55) and one internal and external gateway (192.168.0.254 ).
First, enable route forwarding, and ensure that it takes effect after reboot. Follow these steps:
1: modify/etc/sycctl. conf to enable route forwarding.
[Root @ kook ~] # Vi/etc/sysctl. conf
Net. ipv4.ip _ forward = 1
2: effective immediately
[Root @ kook ~] # Sysctl-p
Net. ipv4.ip _ forward = 1
Net. ipv4.conf. default. rp_filter = 1
Net. ipv4.conf. default. accept_source_route = 0
Kernel. sysrq = 0
Kernel. core_uses_pid = 1
Net. ipv4.tcp _ syncookies = 1
Kernel. msgmnb = 65536
Kernel. msgmax = 65536
Kernel. shmmax = 4294967295
Kernel. shmall = 268435456
Add the NAT of iptables to ensure that the boot route takes effect.
1: Add NAT for iptable
[Root @ kook ~] # Iptables-t nat-a postrouting-s 192.168.10.0/24-o eth0-j MASQUERADE
2: modify the default iptables to ensure that it will still take effect after restart.
[Root @ kook ~] # Iptables-save>/etc/sysconfig/iptables
3: Start iptables
[Root @ kook ~] # Chkconfig iptables on
[Root @ kook ~] # Chkconfig -- list iptables
Iptables 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Test whether the Internet can be accessed in a subnet. Complete.