Myluzh Blog

Linux路由配置

发布时间: 2024-1-14 文章作者: myluzh 分类名称: Linux 朗读文章


0x01 Linux下路由配置命令
1.添加主机路由
route add -host 192.168.1.11 dev eth0
route add -host 192.168.1.12 gw 192.168.1.1
2.添加网络路由
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 eth0
route add -net 192.168.1.0/24 gw 192.168.1.1
3.添加默认网关
route add default gw 192.168.1.1
4.删除路由
route del -host 192.168.1.11 dev eth0
5.删除默认路由
route del default gw 192.168.1.1

0x02 Linux下配置永久路由的几种方式
1.在/etc/rc.local里添加路由信息
route add -net 192.168.1.0/24 dev eth0
# 或者
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
2.在/etc/sysconfig/network里追加
GATEWAY=[网关IP或者网关网卡名称]
3./etc/sysconfig/static-routes
any net 192.168.1.0/24 gw 192.168.1.1
# 或者
any net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

0x03 开启IP转发
1.临时开启
echo "1" > /proc/sys/net/ipv4/ip_forward
2.永久开启
vim /etc/sysctl.conf
net.ipv4.ip_forward=1

标签: linux 路由 route


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/linux/402.html
文章标题:《Linux路由配置

发表评论