Home > Article > Operation and Maintenance > How to add routing commands in linux
Linux add routing command method: 1. Use the route command to add a default route "csharpCopy coderoute add default gw
", and then add a static route. ;2. Use the ip command to add a default route "csharpCopy codeip route add default via dev ", and then add a static route Depend on.
Operating system for this tutorial: linux5.18.14 system, Dell G3 computer.
Linux can add routing commands using the route command or the ip command. The following describes how to use the two methods:
1. Use the route command:
1. Add a default route:
csharpCopy coderoute add default gw <Gateway IP address> <Network interface>
where< Gateway IP address> is the gateway address of the default route to be added,
csharpCopy coderoute add default gw 192.168.1.1 eth0
2. Add a static route:
phpCopy coderoute add -net <Target network address> netmask <Subnet mask> gw <Gateway IP Address> <Network Interface>
where
csharpCopy coderoute add -net 192.168. 2.0 netmask 255.255.255.0 gw 192.168.1.1 eth0
2. Use the ip command:
#1. Add a default route:
csharpCopy codeip route add default via <Gateway IP address> dev <Network interface>
where
csharpCopy codeip route add default via 192.168.1.1 dev eth0
2. Add a static Route:
phpCopy codeip route add <Destination Network Address>/<Subnet Mask> via <Gateway IP Address> dev <Network Interface>
Where
csharpCopy codeip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
The above is the detailed content of How to add routing commands in linux. For more information, please follow other related articles on the PHP Chinese website!