R1
eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.1.0.200
NETMASK=255.255.0.0
eth1
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=10.2.0.200
NETMASK=255.255.0.0
[root@localhost network-scripts]# ip route
10.1.0.0/16 dev eth0 proto kernel scope link src 10.1.0.200 metric 100
10.2.0.0/16 dev eth1 proto kernel scope link src 10.2.0.200 metric 101
临时添加
[root@localhost network-scripts]# ip route add 10.3.0.0/24 via 10.2.0.200 dev eth1
[root@localhost network-scripts]# ip route add 10.4.0.0/24 via 10.2.0.200 dev eth1
[root@localhost network-scripts]# ip route
10.1.0.0/16 dev eth0 proto kernel scope link src 10.1.0.200 metric 100
10.2.0.0/16 dev eth1 proto kernel scope link src 10.2.0.200 metric 101
10.3.0.0/24 via 10.2.0.200 dev eth1
10.4.0.0/24 via 10.2.0.200 dev eth1
[root@localhost network-scripts]# ip route
10.1.0.0/16 dev eth0 proto kernel scope link src 10.1.0.200 metric 100
10.2.0.0/16 dev eth1 proto kernel scope link src 10.2.0.200 metric 101
10.3.0.0/24 via 10.2.0.200 dev eth1
10.4.0.0/24 via 10.2.0.200 dev eth1
R2
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.2.0.201
NETMASK=255.255.0.0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=10.3.0.200
NETMASK=255.255.0.0
ip route add 10.1.0.0/24 via 10.2.0.201 dev eth0
ip route add 10.4.0.0/24 via 10.3.0.200 dev eth1
[root@localhost network-scripts]# ip route
10.1.0.0/24 via 10.2.0.201 dev eth0
10.2.0.0/16 dev eth0 proto kernel scope link src 10.2.0.201 metric 100
10.3.0.0/16 dev eth1 proto kernel scope link src 10.3.0.200 metric 101
10.4.0.0/24 via 10.3.0.200 dev eth1
R3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.3.0.201
NETMASK=255.255.0.0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=10.4.0.200
NETMASK=255.255.0.0
ip route add 10.1.0.0/24 via 10.3.0.201
ip route add 10.2.0.0/24 via 10.3.0.201
[root@localhost network-scripts]# ip route
10.1.0.0/24 via 10.3.0.201 dev eth0
10.2.0.0/24 via 10.3.0.201 dev eth0
10.3.0.0/16 dev eth0 proto kernel scope link src 10.3.0.201 metric 100
10.4.0.0/16 dev eth1 proto kernel scope link src 10.4.0.200 metric 101
1.临时开启,(写入内存,在内存中开启)
echo "1" > /proc/sys/net/ipv4/ip_forward
2.永久开启,(写入内核)
在 vim /etc/sysctl.conf 下
加入此行 net.ipv4.ip_forward = 1
sysctl -p ----加载一下
[root@localhost ~]# sysctl -a |grep "ip_forward" ----查看一下
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0