Linux配置IP路由

 没配之前

命令

ifconfig eth0 192.168.1.101 netmask 255.255.255.0 up

ifconfig eth1 192.168.1.102 netmask 255.255.255.0 up

配置之后

没配之前

 配置之后

永久开启

临时开启 

echo 1 > /proc/sys/net/ipv4/ip_forward

 route add -net 192.168.1.100/24  gw 192.168.2.100 dev eth0   

添加路由时报错

route: netmask doesn't match route address

-net 后加的是网段,不是IP。
试试 192.168.1.0

route add -net 192.168.1.0/24  gw 192.168.2.100 dev eth0   

删除ip

ip addr del 192.168.1.102 dev eth1

删除路由

route del default

route del -net 10.0.0.0 netmask 255.255.0.0 gw 0.0.0.0

原文地址:https://www.cnblogs.com/code1992/p/13684247.html