深入探究如何修改Linux靜態路由
修改Linux靜態路由最重要的就是修改外網網關,其實其修改語句也很簡單,于是我研究了一下如何修改Linux靜態路由以及相關語句,在這里拿出來和大家分享一下,希望對大家有用。
- routeadd-net10.10.101.0netmask255.255.255.0gw10.10.100.1
- catroute-eth0
- 10.10.101.0/24via10.10.100.1deveth0
- /etc/rc.d/init.d/networkrestart
- netstat-r
- [root@1314itnetwork-scripts]#cat/etc/sysconfig/network-scripts/route-eth0
- 123.123.123.0via156.156.156.156deveth0
- [root@1314itnetwork-scripts]#
已測試成功重啟網絡會執行此文件,內網:有兩個網段10.10.100.0/24和10.10.101.0/24,服務器ip:a.b.c.d外網網關e.f.g.h服務器內網卡10.10.100.254,內網10.10.101.0/24網段的機器無法訪問10.10.100.254這臺機器。登陸服務器查看Linux靜態路由表:
- [root@wwwconf]#netstat-r
- KernelIProutingtable
- DestinationGatewayGenmaskFlagsMSSWindowirttIface
- 10.10.100.0*255.255.255.0U000eth0
- 169.254.0.0*255.255.0.0U000eth1
- defaulte.f.g.h0.0.0.0UG000eth1
因此可以看到在10.10.100.254服務器上無法看到10.10.101.0/24的路由選擇表路由條目,因此可以兩種方法添加,臨時性的:routeadd-net10.10.101.0netmask255.255.255.0gw10.10.100.1,但重新啟動后就會失效.因此在/etc/sysconfig/network-scripts/目錄下建立文件。因為我們是做內網的Linux靜態路由,并且內網網卡為eth0,因此我們建立route-eth0文件如下:
- [root@wwwnetwork-scripts]#catroute-eth0
- 10.10.101.0/24via10.10.100.1deveth0
- [root@wwwnetwork-scripts]#/etc/rc.d/init.d/networkrestart
- [root@wwwnetwork-scripts]#netstat-r
- KernelIProutingtable
- DestinationGatewayGenmaskFlagsMSSWindowirttIface
- 10.10.101.010.10.100.1255.255.255.0UG000eth0
- 10.10.100.0*255.255.255.0U000eth0
- 169.254.0.0*255.255.0.0U000eth1
- defaulte.f.g.h0.0.0.0UG000eth1
修改外網網關如下:
- [root@wwwconf]#cat/etc/sysconfig/network
- NETWORKING=yes
- HOSTNAME=www.test.cn
- GATEWAY=e.f.g.h
- source:google