how i add route

General support questions
good_face
Posts: 48
Joined: 2019/10/15 13:29:09

how i add route

Post by good_face » 2020/09/11 14:37:14

I want to add a route to this server. How do I add a route. After adding a route, Should the network service be restart. If I do, the server access is broken?

I intend to use this command for bond0. Can I add with this command. ( route add -net IP netmask IP gw IP )

Thanks for helping
Last edited by good_face on 2020/09/11 18:22:37, edited 2 times in total.

User avatar
jlehtone
Posts: 3180
Joined: 2007/12/11 08:17:33
Location: Finland

Re: how i add route

Post by jlehtone » 2020/09/11 15:22:41

If you want to change configuration, then you should use whatever you are using to configure the network settings.
While you can temporarily change runtime config, it is important to store more persistent config too.

The default in CentOs 7 is to use NetworkManager.service. The alternative is network.service.
If you get main bits of config from DHCP server with either of those, then your DHCP server can offer the additional routes too.

The "route" is a tool that could have been forgotten two decades ago, when iproute2 package did appear.
I like the output of ip ro because it shows routes in same syntax that ip ro add will accept.


It seems that you do already have some static routes. (Hard to tell, I never did learn to read output of 'route'.)
How did you configure those?

good_face
Posts: 48
Joined: 2019/10/15 13:29:09

Re: how i add route

Post by good_face » 2020/09/11 17:21:14

I'm sorry, I didnt understand. I'll add a new route here what are the how to add commands.

Thraex
Posts: 45
Joined: 2019/05/14 19:50:28

Re: how i add route

Post by Thraex » 2020/09/11 17:30:56

I usually use nmcli to add routes. Command would be:

nmcli c m NIC +ipv4.routes "destination/subnet gateway"

example: nmcli c m ens33 +ipv4.routes "192.168.10.0/24 192.168.1.254"

A few notes, if you're routing to a specific address you don't need to add the subnet and if you want to replace routes remove the + from ipv4.routes.
nmcli has a decent example man page as well: man nmcli-examples

good_face
Posts: 48
Joined: 2019/10/15 13:29:09

Re: how i add route

Post by good_face » 2020/09/11 18:00:23

is it true ? i will add route like that . the method may be different. I just want to find out if it's true
Last edited by good_face on 2020/09/12 18:39:40, edited 1 time in total.

good_face
Posts: 48
Joined: 2019/10/15 13:29:09

static route

Post by good_face » 2020/09/12 10:20:47

i will add static route but file is empt so why it is empty . how i can add new route

i want to add this 192.168.1.0/24 via 192.168.1.1

Where are the rope definitions I see written ?
Last edited by good_face on 2020/09/12 18:39:25, edited 1 time in total.

User avatar
TrevorH
Forum Moderator
Posts: 29915
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: static route

Post by TrevorH » 2020/09/12 13:47:07

i want to add this 192.168.1.0/24 via 192.168.1.1
You don't seem to have an interface on that subnet so you don't have a way to get to 192.168.1.1 without sending the packets out via your default route.

Use ip route get $ip and it will tell you which route it will take.

Edit: merged this and your other thread since they appear to be the same thing.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

good_face
Posts: 48
Joined: 2019/10/15 13:29:09

Re: how i add route

Post by good_face » 2020/09/12 14:12:38

I guess I asked my question wrong. my question is, I'll add a new route. everyone says Write a new route into /etc/sysconfig/network-scripts/route-interface. but I see the file/etc/sysconfig/network-scripts / route-bond empty. why is the file hollow and I see routes when I type the route command. I wrote down the IP addresses I gave as examples . do not pay attention to the ip address I will write a different ip address. a different method for writing a route is written ? how do I see it when I add a new route and type the route command. I don't use linux. I just started learning

User avatar
TrevorH
Forum Moderator
Posts: 29915
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: how i add route

Post by TrevorH » 2020/09/12 14:23:21

You only need to use those route files if you are adding non-standard routes. All interfaces automatically get used for routing the traffic for their local subnet without needing to add a specific route. For example, if you have an interface called eth9 and it has an ip address of 192.168.66.5 with netmask 255.255.255.0 then it automatically gets a route added to say that 192.168.66./024 goes via it.

For your example where you want to ip route add 192.168.1.0/24 via 192.168.1.1, that can only work if you have an interface that knows how to get to 192.168.1.1 in the first place so it's not going to work. You can only route via things that it knows how to get to in the first place so if you run ip route get 192.168.1.1 it will currently tell you that it will go via your default route since you have no interface on 192.168.1.0/24 and nor do you have an existing route that tells it how to get to 192.168.1.1. And if you did have an interface on 192.168.1.0/24 then you wouldn't need to add that route anyway as 192.168.1.1 is within 192.168.1.0/24 so it would already know that it had to use that interface to get there.

Also, the route command is deprecated and has been for about 15 years. Please use the ip route command as it's better maintained, gives better output and knows things that route does not.

Also, if you're going to ask for help for networking questions, it is important to use the actual information you want to use and not obscure actual ip addresses and routes. That way will just lead to misleading answers and wrong information that won't help you.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

good_face
Posts: 48
Joined: 2019/10/15 13:29:09

Re: how i add route

Post by good_face » 2020/09/12 14:32:25

I got it. I'll write a route definition for 10.183.248.0. gw: 10.181.20.65 mask 255.255.255.0 how can I add a route in this way. can you type the command? for my machine. I'd be very happy if you'd write how to write or do it because I'm a beginner. I don't want it to be deleted when the server is restarted. When I add a new route, will I reboot the service? And also running apps on it will be affected before reboot the service ?

thank you very much

Post Reply

Return to “CentOS 7 - General Support”