添加设置路由route
route命令解析、永久路由设置、跨⽹段互通
⼯具/原料
Linux系统命令⾏
⽅法/步骤
1. route命令解析: 添加到主机的路由:
# route add –host 192.168.1.10 dev eth0# route add –host 192.168.1.10 gw 192.168.1.1添加到⽹络的路由
# route add –net 192.168.1.0 netmask 255.255.255.0 eth0
# route add –net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1# route add –net 192.168.1.0/24 eth1 添加默认⽹关:
# route add default gw 192.168.1.1 删除路由:
# route del –host 192.168.1.10 dev eth02.
添加永久路由⽅法:⽅法⼀:
# vi /etc/rc.local(添加到末尾)语句:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.2.254⽅法⼆:
# vi /etc/sysconfig/network (添加到末尾)语句:
GATEWAY=gw-ip 或者 GATEWAY=gw-dev⽅法三:
# vi /etc/sysconfig/static-routes (没有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⽅法四:
开启 IP 转发:
# echo \"1\" >/proc/sys/net/ipv4/ip_forward (临时)# vi /etc/sysctl.conf --> net.ipv4.ip_forward=1 (永久开启)END
注意事项
⽅法都是在Centos系统下测试过,能够⽣效。
如果对应⽂件夹没有该配置⽂件,可以⾃⼰建⼀个。