How To Add Ip Route In Linux?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. Open the terminal window and enter the “route” command.
2. Enter the following syntax to add a specific IP route: route add -net <IP address> netmask <subnet mask> gw <gateway IP>. For example, route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
3. To add a default gateway, enter the following syntax: route add default gw <gateway IP>
4. To add a persistent route, create a file in /etc/sysconfig/network-scripts/ with a name such as “route-eth0” that contains the same route command as used above.
5. Finally, enter the command “/etc/init.d/network restart” or reboot the system to apply the changes.
The ‘ip route’ command in Linux is used to set up static routes to specific hosts or networks via an interface. To add a static route to the routing table, you can use the following syntax:
sudo ip route add [Destination IP]/[Subnet Mask] via [Gateway IP] dev [Interface]
For example, if you want to add a route to the 192.168.1.0/24 network via the gateway 192.168.0.1 using the eth0 interface, you would run the following command:
sudo ip route add 192.168.1.0/24 via 192.168.0.1 dev eth0
To add an IP route in Linux, you can use the “ip route” command. For example, to add a route to 192.168.1.0/24 via the gateway 192.168.2.1, you would use the following command:
sudo ip route add 192.168.1.0/24 via 192.168.2.1