Centos6.5 for routing, NAT, and DHCP

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.