1. you must install iptables. You must install iptables. otherwise, nat cannot be configured. # Iptables-v: view the iptables version. 2. start configuring NAT with dual NICs (single NIC is also available, but not recommended). you must set the NIC ip address to a fixed ip address. do not dynamically obtain the ip outer IP address: 135.252.139.28 the intranet IP address is: 192
NAT configuration in Linux
1. you must install iptables.
RequiredIptablesOtherwise, nat cannot be configured.
# Iptables-v: view the iptables version.
2. start configuration
Configure NAT with dual NICs (single NIC is also available, but not recommended ),
Make sure to set the NIC ip address to a fixed ip address. do not obtain the ip address dynamically.
Internet IP address: 135.252.139.28
Intranet IP address: 192.168.1.1
Next let's take a look at my nic ip configuration
# Vi/etc/../network-scripts/ifcfg-eth1
DEVICE = eth1
BOOTPROTO = static
BROADCAST = 135.252.139.255
IPADDR = 135.252.139.1
NETMASK = 255.255.255.0
NETWORK = 135.252.139.0
ONBOOT = yes
TYPE = Ethernet
# Vi/etc/./network-scripts/ifcfg-eth0
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
IPADDR = 192.168.1.1
NETMASK = 255.255.255.0
Look at the dns situation, this generally does not need to be changed, the intranet uses the Internet dns can be
# Vi/etc/resolv. conf
Nameserver 135.252.142.166 // Internet DNS address
Nameserver 135.252.44.59 // The backup DNS address of the Internet
Modify Gateway
# Vi/etc/sysconfig/network
NETWORKING = yes
HOSTNAME = tpwb
GATEWAY = 135.252.139.1 your GATEWAY (the GATEWAY of 135.252.139.28), this is not needed if it is written in the ifcong-eth1
View route information
# Route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
135.252.139.0*255.255.255.0 U 0 0 eth1
192.168.1.0*255.255.255.0 U 0 0 0 eth0
169.254.0.0*255.255.0.0 U 0 0 0 eth1
Default 135.252.139.1 0.0.0.0 UG 0 0 0 Eth1
Ensure that the default value is 135.252.139.1.
Restart the NIC
# Service named restart
Stop named:
Start named: [OK]
Now the preparations are almost done!
I enter a fixed IP address.
[Root @ tpwb ~] # Iptables-t nat-a postrouting-s 192.168.1.0/24-o eth1-j SNAT -- to 135.252.139.28
If you are using A dial-up Internet access, iptables-t nat-a postrouting-s 192.168.1.0/24-o ppp0-j MASQUERADE
Enable the ip forwarding function.
# Echo 1>/proc/sys/net/ipv4/ip_forward
1. Save The IPTABLES configuration.
# Etc/rc. d/init. d/iptables save
2. View # vi/etc/rc. d/rc. local.
#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full Sys V style init stuff.
Touch/var/lock/subsys/local
Echo 1>/proc/sys/net/ipv4/ip_forward. this line is added!
~
~
Save and exit.
3, # ntsysv
Ntsysv 1.3.13.3-(C) 2000-2001 Red Hat, Inc.
Lqqqqqqqqqqqqqqqq U service tqqqqqqqqqqqqqqqqqqk
X
X what services do you want to automatically start? X
X
X [] FreeWnn # x
X [] NetworkManager a x
X [*] acpid a x
X [] amanda a x
X [] amandaidx a x
X [] amd a x
X [] amidxtape a x
X [*] anacron a x
X
X lqqqqqqk lqqqqqqqqk x
X OK x cancel x
X mqqqqqqj x
X
X
Mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
Press You can obtain details about a service.
In named and iptables [], click a space to see the "*" icon. "OK" indicates automatic loading upon startup!
Restart
[Root @ tpwb rc. d] # reboot