根据现有网络拓扑,利用一台Linux充当Route的角色,实现内外网互通,具体配置如下:
首先充当Linux Route的主机具备两块网卡,进行内外相连;进入/etc/sysconfig/network-scripts/,分别对ifcfg-eth0;ifcfg-eth1进行配置;具体信息如图:
上面这个网关是在eth0上进行设置,因为eth0连接的是外网;这个决定了网络数据包的流向;如果设置不对,内网用户将无法上网;数据包也就无法转发出去;
网口配置好相关信息后,还需要开启IP路由转发传递;
[root@server ~]# echo "1" > /proc/sys/net/ipv4/ip_forward
也可以直接编辑/etc/sysctl.conf文件
将# Controls IP packet forwarding
net.ipv4.ip_forward = 0改成1即可
然后重启网络,并观察路由表;
[root@server ~]# /etc/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Disabling IPv4 packet forwarding: net.ipv4.ip_forward = 0 [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]