实验环境:

Route(双网卡Linux主机):

    eth0(外网网卡):

        IPADDR=10.100.56.46

        NETMASK=255.255.255.0

        GATEWAY=10.100.56.1

    eth1(内网网卡):

        IPADDR=174.36.10.1

        NETMASK=255.255.255.0

wKiom1ZlMyegALugAABKap1Zglo567.png

Client(单网卡Linux主机):

    eth0:

        IPADDR=174.36.10.2

        NETMASK=255.255.255.0

        GATEWAY=174.36.10.1

vi /etc/sysconfig/network //配置网关

wKiom1ZlNByTaga1AAAUgpicVXE123.png

wKioL1ZlM8LzQMSaAAA2kIi1IuU205.png

实验步骤1:

    编辑sysctl.conf文件打开IP转发。

    vi /etc/sysctl.conf

    把net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1

    键入sysctl -p  //让配置立即生效

实验步骤2:
    修改iptables文件
    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
    键入service iptables save //保存iptables配置

进行到这里路由和nat设置完成,cilent可以ping通外网

wKioL1ZlNSOTKrANAAAkiUZ4EEE805.png

实验步骤3:配置DHCP

yum –y install dhcp   //安装DHCP服务

cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak    //备份dhcpd.conf文件

vi /etc/dhcp/dhcpd.conf  //编辑配置文件

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;
}

wKioL1ZlRJShUXtEAAAkwFPnhG0439.png

service dhcpd start  //启动服务

chkconfig dhcpd on  //设为开机启动

vi /etc/sysconfig/dhcp  //指定DHCP服务的网络接口

DHCPDARGS=eth1

wKioL1ZlRT2zoHlZAAAQAttmV7M736.png

注释掉client的静态IP配置,BOOTPROTO更改为dhcp

wKioL1ZlRdmgOeFkAAAgzzjUjus036.png

service network restart //重启网络服务

wKioL1ZlRoeymsieAAAes0uMaNs892.png

查看IP地址(已经获取到IP:174.36.10.20)

wKioL1ZlSJWj68WUAAA7ZcKprqE187.png

ping www.baidu.com

wKiom1ZlSFmjNph0AAAbwSjrEOY833.png