linux系统怎么添加路由?

linux系统怎么添加路由?,第1张

linux下添加路由的方法:

一:使用 route 命令添加

使用route 命令添加路由,机器重启或者网卡重启后路由就失效了,方法

二:在linux下设置永久路由的方法:

1.在/etc/rc.local里添加

方法:

2.在/etc/sysconfig/network里添加到末尾

方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev

3./etc/sysconfig/static-router :

linux 添加永久静态路由

Linux 的路由功能:

# route 命令添加的路由,机器重启或者网卡重启后就没掉了,在linux下设置永久路由的方法:

1.在/etc/rc.local里添加

2.在/etc/sysconfig/network里添加到末尾

3./etc/sysconfig/static-router :

any net x.x.x.x/24 gw y.y.y.y

开启 IP 转发:

一、使用route命令添加

使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:

A、添加到主机的路由

route add –host 192.168.1.10 dev eth0

route add –host 192.168.1.10 gw 192.168.1.1

B、添加到网络的路由

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

C、添加默认网关

route add default gw 192.168.1.1

D、删除路由

route del –host 192.168.1.10 dev eth0

二、添加永久路由

A、# vi /etc/rc.local(添加到末尾) 《Linux就该这么学》学习linux

语句:

route add -net 192.168.3.0/24 dev eth0

route add -net 192.168.2.0/24 gw 192.168.2.254

[root@admin ~]# cat /etc/rc.local

/usr/bin/freshclam --daemon

/sbin/route add -net 192.168.168.0/24 gw 172.16.16.1

/etc/init.d/ipsec restart

/usr/bin/l2tpset

/usr/local/sbin/xl2tpd

iptables --table nat --append POSTROUTING --jump MASQUERADE

/etc/init.d/ipsec restart

/usr/bin/l2tpset

/usr/local/sbin/xl2tpd

/sbin/route add -net 192.168.99.108/30 gw 172.16.16.1

/sbin/route add -net 10.50.0.188/30 gw 172.16.16.1

/sbin/route add -net 103.227.72.32/27 gw 172.16.16.30

/sbin/route add -host 118.188.20.34 gw 172.16.16.30

/sbin/route add -net 192.168.168.0/24 gw 172.16.16.1

/sbin/route add -host 103.232.215.131 gw 172.16.16.1

/sbin/route add -net 103.227.72.160/27 gw 172.16.16.30

/sbin/route add -host 220.181.163.1 gw 172.16.16.30

linux下添加路由的方法:

一:使用 route 命令添加

使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:

//添加到主机的路由

# route add –host 192.168.168.110 dev eth0

# route add –host 192.168.168.119 gw 192.168.168.1

//添加到网络的路由

# route add –net IP netmask MASK eth0

# route add –net IP netmask MASK gw IP

# route add –net IP/24 eth1

//添加默认网关

# route add default gw IP

//删除路由

# route del –host 192.168.168.110 dev eth0

二:在linux下设置永久路由的方法:

1.在/etc/rc.local里添加

方法:

route add -net 192.168.3.0/24 dev eth0

route add -net 192.168.2.0/24 gw 192.168.3.254

2.在/etc/sysconfig/network里添加到末尾

方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev

3./etc/sysconfig/static-router :

any net x.x.x.x/24 gw y.y.y.y


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11530978.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存