Linux-如何添加路由表
linux下靜態(tài)路由修改命令
方法一:
添加路由
route add -net 192.168.0.0/24 gw 192.168.0.1
route add -host 192.168.1.1 dev 192.168.0.1
刪除路由
route del -net 192.168.0.0/24 gw 192.168.0.1
add 增加路由
del 刪除路由
-net 設(shè)置到某個網(wǎng)段的路由
-host 設(shè)置到某臺主機的路由
gw 出口網(wǎng)關(guān) IP地址
dev 出口網(wǎng)關(guān) 物理設(shè)備名
增 加默認(rèn)路由
route add default gw 192.168.0.1
默認(rèn)路由一條就夠了
route -n 查看路由表
方法二:
添加路由
ip route add 192.168.0.0/24 via 192.168.0.1
ip route add 192.168.1.1 dev 192.168.0.1
刪除路由
ip route del 192.168.0.0/24 via 192.168.0.1
add 增加路由
del 刪除路由
via 網(wǎng)關(guān)出口 IP地址
dev 網(wǎng)關(guān)出口 物理設(shè)備名
增加默認(rèn)路由
ip route add default via 192.168.0.1 dev eth0
via 192.168.0.1 是我的默認(rèn)路由器
查看路由信息
ip route
保存路由設(shè)置,使其在網(wǎng)絡(luò)重啟后任然有效
在/etc/sysconfig/network-script/目錄下創(chuàng)建名為route- eth0的文件
vi /etc/sysconfig/network-script/route-eth0
在此文件添加如下格式的內(nèi)容
192.168.1.0/24 via 192.168.0.1
重啟網(wǎng)絡(luò)驗證
/etc/rc.d/init.d/network中有這么幾行:
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi
也就是說,將靜態(tài)路由加到/etc/sysconfig/static-routes 文件中就行了。
如加入:
route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1
則static-routes的格式為
any net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1
總結(jié)
以上是生活随笔為你收集整理的Linux-如何添加路由表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 出口退税退多少个点 出口退税几个点可以退
- 下一篇: 香港恒生科技指数 什么是恒生科技指数