方法为:1、添加到主机的路由,“# route add –host 192.168.1.11 dev eth0”;2、添加到网络的路由,“# route add –net 192.168.1.0/24 eth1”。
本教程操作环境:centos7系统、thinkpad t480电脑。
The school operating environment: the Centos7 system, the thinkpad t480 computer.
具体操作方法如下:
The specific methods of operation are as follows:
一、使用 route 命令添加?
I. Add using root command?
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
The route added by the roote command is disabled when the machine reboots or the netcard reboots:
//添加到主机的路由?
// Add to host route?
# route add –host 192.168.1.11 dev eth0 # route add –host 192.168.1.12 gw 192.168.1.1
//添加到网络的路由
/ / Add to network route
# route add –net 192.168.1.11 netmask 255.255.255.0 eth0 # route add –net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1 # route add –net 192.168.1.0/24 eth1
//添加默认网关
// Add default gateway
# route add default gw 192.168.2.1
//删除路由
// Delete route
# route del –host 192.168.1.11 dev eth0
二:在linux下设置永久路由的方法:
Two: How to set the permanent route under linux:
https://www.php.cn/faq/etc/sysconfig/static-routes : any net 192.168.3.0/24 gw 192.168.3.254 any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
使用static-routes的方法是最好的。无论重启系统和service network restart 都会生效。
The best way to use a state-rootes is to reboot the system and service network restart.
static-routes文件又是什么呢,这个是network脚本执行时调用的一个文件,这个文件的放置在/etc/sysconfig目录下,在network脚本中的位置是:
What is the status-routes file, which is a file called for during the implementation of the networkwork script, which is placed in the /etc/sysconfig directory and is located in the network script:
# 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
从这段脚本可以看到,这个就是添加静态路由的方法,static-routes的写法是
As can be seen from this script, this is the way to add a static route.
any net 192.168.0.0/16 gw 网关ip。
(推荐学习:linux教程)
(Recommended for study: linux )
以上就是route add如何添加静态路由的详细内容,更多请关注php中文网其它相关文章!
This is how the roote add adds more details about the static route. Please pay more attention to php and other relevant articles in Chinese!
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论