CentOS双网卡配置默认路由
程序员文章站
2024-02-13 19:46:40
...
CentOS使用双网卡时,如果要指定其中一个网卡的网关作为默认路由,不能直接用route命令进行修改,或者只是删除其中一个默认路由。例如:
[[email protected]:0]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:A6:4F:9A
inet addr:99.1.1.1 Bcast:99.1.16.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:264636824 errors:0 dropped:0 overruns:0 frame:0
TX packets:1630865 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24486306913 (22.8 GiB) TX bytes:2105592006 (1.9 GiB)
eth1 Link encap:Ethernet HWaddr 00:50:56:A6:7E:F4
inet addr:192.168.127.8 Bcast:192.168.127.8 Mask:255.255.255.255
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:132847578 errors:0 dropped:0 overruns:0 frame:0
TX packets:132847578 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:51965842204 (48.3 GiB) TX bytes:51965842204 (48.3 GiB)
有99.1.1.1和192.168.127.8两个IP。如果希望默认路由从99.1.1.1的接口出:
cd /etc/sysconfig/network-scripts
echo 'iif eth1 table 1
from 192.168.127.8 table1' > rule-eth1
echo '192.168.127.0/24 dev eth1 table 1
default via 192.168.127.253 dev eth1 table 1' > route-eth1
重启网卡即可。
上一篇: matprolib可视化处理
下一篇: 动态路由协议-RIP