", and then add a static route; 2. Use the ip command to add a default route Route "csharpCopy codeip route add default via dev " and then add a static route Depend on."/> ", and then add a static route; 2. Use the ip command to add a default route Route "csharpCopy codeip route add default via dev " and then add a static route Depend on.">

Home  >  Article  >  Operation and Maintenance  >  How to add routing commands in linux

How to add routing commands in linux

小老鼠
小老鼠Original
2023-06-08 18:04:459920browse

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.

How to add routing commands in linux

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, is the network interface through which the route is to be routed, for example:

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 is the destination network address of the static route to be added, is the subnet of the destination network Netmask, is the gateway address of static routing, is the network interface through which the route is routed, for example:

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 is the gateway address of the default route to be added, is the network interface through which the route is to be routed, for example:

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 / is the target network address and subnet mask of the static route to be added, is the gateway address of the static route , is the network interface through which the route is to be routed, for example:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to rename LinuxNext article:How to rename Linux