Centos6.5 for routing, NAT, and DHCP
Lab environment:
Route (dual Nic Linux host ):
Eth0 (Internet Nic ):
IPADDR = 10.100.56.46
NETMASK = 255.255.255.0
GATEWAY = 10.100.56.1
Eth1 (intranet Nic ):
IPADDR = 174.36.10.1
NETMASK = 255.255.255.0
Client (single Nic Linux host ):
Eth0:
IPADDR = 174.36.10.2
NETMASK = 255.255.255.0
GATEWAY = 174.36.10.1
Vi/etc/sysconfig/network // configure the Gateway
Step 1:
Edit the sysctl. conf file to enable IP forwarding.
Vi/etc/sysctl. conf
Change net. ipv4.ip _ forward = 0 to net. ipv4.ip _ forward = 1.
Type sysctl-p // to make the configuration take effect immediately
Step 2:
Modify the iptables File
Iptables-F
Iptables-t nat-a postrouting-o eth0-j MASQUERADE
Iptables-t filter-a forward-I eth0-o eth1-j ACCEPT
Iptables-t filter-a forward-I eth1-o eth0-j ACCEPT
Type service iptables save // save iptables configuration
After completing the routing and nat settings, cilent can ping the internet.
Step 3: Configure DHCP
Yum-y install dhcp // install DHCP Service
Cp/etc/dhcp/dhcpd. conf/etc/dhcp/dhcpd. conf. bak // back up the dhcpd. conf file
Vi/etc/dhcp/dhcpd. conf // edit the configuration file
Subnet 174.36.10.0 netmask 255.255.255.0 {
Range 174.36.10.20 174.36.10.250;
Option domain-name-servers 114.114.114.114;
Option routers 174.36.10.1;
Option broadcast-address 174.36.10.255;
Default-lease-time 600;
Max-lease-time 7200;
}
Service dhcpd start // start the service
Chkconfig dhcpd on // set to boot
Vi/etc/sysconfig/dhcp // specify the network interface of the DHCP service
DHCPDARGS = eth1
Comment out the static IP configuration of the client, and change BOOTPROTO to dhcp.
Service network restart // restart the network service
View the IP address (obtained IP: 174.36.10.20)
Pingwww.baidu.com