Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
routes_if "default via/gw" syntax?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Thu Mar 07, 2024 11:57 am    Post subject: routes_if "default via/gw" syntax? Reply with quote

I have:

Code:

config_enp2s0="172.16.16.253 netmask 255.255.255.0 broadcast 172.16.16.255"
routes_enp2s0="default gw 192.168.50.1"


When I boot or restart net.enp2s0 I get no default route? I can add it manually by "route add default gw 192.168.50.1".

What I want to end up with is a routing table like this:

Code:

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.50.1    0.0.0.0         UG    0      0        0 enp60s0
172.16.16.0     0.0.0.0         255.255.255.0   U     1002   0        0 enp2s0
192.168.50.0    0.0.0.0         255.255.255.0   U     1003   0        0 enp60s0


What is the syntax to add this default route to the net file or elsewhere.

Another solution could be to specify which dhcp server I should accept a default gw from on a multi-nic host as Iasked in https://forums.gentoo.org/viewtopic-p-8818732.html#8818732 but here I was only able to disable all gateways provided by dhcpcd.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1896

PostPosted: Thu Mar 07, 2024 1:24 pm    Post subject: Reply with quote

pgu wrote:
Code:

config_enp2s0="172.16.16.253 netmask 255.255.255.0 broadcast 172.16.16.255"
routes_enp2s0="default gw 192.168.50.1"
This should be: (also including CIDR notation to skip an internal netifrc step)
Code:

config_enp2s0="172.16.16.253/24"
routes_enp2s0="default via 192.168.50.1"
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Thu Mar 07, 2024 3:07 pm    Post subject: Reply with quote

I should have been more specific. In the title I mentioned both via and gw. I tried both and none of them worked.
Changing to CIDR notation does not seem to help:

Code:

# grep enp2s0 /etc/conf.d/net | grep -v ^#
config_enp2s0="172.16.16.253/24"
routes_enp2s0="default via 192.168.50.1"
# /etc/init.d/net.enp2s0 restart
 * Unmounting network filesystems ...                                                                           [ ok ]
 * Stopping named ...                                                                                           [ ok ]
 * Stopping dhcpd ...                                                                                           [ ok ]
 * Bringing down interface enp2s0
 * Bringing up interface enp2s0
 *   172.16.16.253/24 ...                                                                                       [ ok ]
 *   Adding routes
 *     default via 192.168.50.1 ...
Error: Nexthop has invalid gateway.                                                                             [ !! ]


I can run the command on the command where it's not associated with an interface:

Code:

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.16.0     0.0.0.0         255.255.255.0   U     1002   0        0 enp2s0
192.168.50.0    0.0.0.0         255.255.255.0   U     1003   0        0 enp60s0
# route add default gw 192.168.50.1
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.50.1    0.0.0.0         UG    0      0        0 enp60s0
172.16.16.0     0.0.0.0         255.255.255.0   U     1002   0        0 enp2s0
192.168.50.0    0.0.0.0         255.255.255.0   U     1003   0        0 enp60s0


How can I do this in the net file? Can I specify a static route associated with the dhcp assigned interface?

I tried this, but still no default route:
Code:

config_enp60s0="dhcp"
routes_enp60s0="default via 192.168.50.1"
Back to top
View user's profile Send private message
pa4wdh
l33t
l33t


Joined: 16 Dec 2005
Posts: 881

PostPosted: Thu Mar 07, 2024 4:50 pm    Post subject: Reply with quote

Code:

# grep enp2s0 /etc/conf.d/net | grep -v ^#
config_enp2s0="172.16.16.253/24"
routes_enp2s0="default via 192.168.50.1"
# /etc/init.d/net.enp2s0 restart
 * Unmounting network filesystems ...                                                                           [ ok ]
 * Stopping named ...                                                                                           [ ok ]
 * Stopping dhcpd ...                                                                                           [ ok ]
 * Bringing down interface enp2s0
 * Bringing up interface enp2s0
 *   172.16.16.253/24 ...                                                                                       [ ok ]
 *   Adding routes
 *     default via 192.168.50.1 ...
Error: Nexthop has invalid gateway.                                                                             [ !! ]

The error tells you exactly the problem: The next hop/gateway should be local to one of your interfaces. In your case 192.168.50.1 is not within 172.16.16.253/24. Either fix your gateway or your subnet, they can't be both correct.
Is doesn't matter if this configuration is static in /etc/conf.d/net or via dhcp, it simply can't work.
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse @world

My shared code repository: https://code.pa4wdh.nl.eu.org
Music, Free as in Freedom: https://www.jamendo.com
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1896

PostPosted: Thu Mar 07, 2024 5:30 pm    Post subject: Reply with quote

The simple answer is to let dhcp assign the gateway (via enp60s0). enp2s0 should not have any such route.

However, the real shenanigans is informing your router to send traffic to 172.16.16.0/24. Often this is difficult or impossible if you don't control it fully. The machine needs a reservation in the DHCP server at minimum.
Some NAT techniques can be used to do the translation on the local machine.
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Fri Mar 08, 2024 6:23 am    Post subject: Reply with quote

pa4wdh wrote:

The error tells you exactly the problem: The next hop/gateway should be local to one of your interfaces. In your case 192.168.50.1 is not within 172.16.16.253/24. Either fix your gateway or your subnet, they can't be both correct.
Is doesn't matter if this configuration is static in /etc/conf.d/net or via dhcp, it simply can't work.


I understand this and this is the reason for my last question above. As I mentioned earlier it works when I apply the command "route add default gw 192.168.50.1" manually. But how do I do this in the "net" file? As I also mentioned above I tried to associate it with the interface connected to this route using the "routes_enp2s0" above, but this does not affect the routing table at all.
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Fri Mar 08, 2024 6:25 am    Post subject: Reply with quote

grknight wrote:

The simple answer is to let dhcp assign the gateway (via enp60s0). enp2s0 should not have any such route.


This is what I tried initially and resulted in two default routes as I could not figure out how to disable the gateway assigned to the other interface as described in https://forums.gentoo.org/viewtopic-t-1167688.html. However, I will try adding the interface option as suggested by "flexibeast" and go back to using dhcp for all the interfaces.
Back to top
View user's profile Send private message
pa4wdh
l33t
l33t


Joined: 16 Dec 2005
Posts: 881

PostPosted: Fri Mar 08, 2024 6:04 pm    Post subject: Reply with quote

pgu wrote:

I understand this and this is the reason for my last question above. As I mentioned earlier it works when I apply the command "route add default gw 192.168.50.1" manually. But how do I do this in the "net" file? As I also mentioned above I tried to associate it with the interface connected to this route using the "routes_enp2s0" above, but this does not affect the routing table at all.

Even if you can actually run this command and execute it successfully, the route will be ineffective unless there is a second interface providing you connectivity to a network that contains 198.169.50.1. If this is the case you'll have to set up a dependency to make sure that interface is brought up before this one.
Other than that, the only thing i can think of is that the old tools (ifconfig/route) behave a little different from the new tools (iproute2 aka the ip command, used by the netifrc). To force netifrc to use ifconfig put modules="!iproute2" in your /etc/conf.d/net
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse @world

My shared code repository: https://code.pa4wdh.nl.eu.org
Music, Free as in Freedom: https://www.jamendo.com
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Fri Mar 29, 2024 7:34 am    Post subject: Reply with quote

pa4wdh wrote:

Even if you can actually run this command and execute it successfully, the route will be ineffective unless there is a second interface providing you connectivity to a network that contains 198.169.50.1.


I assume that is a typo and that you mean 192.168.50.1 (as I haven't mentioned the above network earlier).

There are multiple interfaces, enp60s0 is connected to the 192.168.50.0/24 network and enp2s0 is connected to the 172.16.16.0/24 network.


pa4wdh wrote:

If this is the case you'll have to set up a dependency to make sure that interface is brought up before this one.


That's basically my question. How do I do this using the "net" or any other file(s)?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54572
Location: 56N 3W

PostPosted: Fri Mar 29, 2024 8:23 am    Post subject: Reply with quote

pgu,

Do not set a default route for enp2s0
The local net route to 172.16.16.0/24 is free.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Sat Mar 30, 2024 6:41 am    Post subject: Reply with quote

NeddySeagoon wrote:
pgu,

Do not set a default route for enp2s0
The local net route to 172.16.16.0/24 is free.


I don't set a default route to the local net, but I need a default gateway for this network to be able to reach the upstream network and finally the internet.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54572
Location: 56N 3W

PostPosted: Sat Mar 30, 2024 11:14 am    Post subject: Reply with quote

pgu,

Set exactly one default route.

Having two or more default routes means that the kernel will always choose the one with the lowest 'cost'.
That's the metric in the routing table. You are free to define the metric.
However, it boils down to still only having a single default route.

If the default route is outside of your subnet, then you need a host route that says how to reach it.
That's a /32 in CDIR notation
Now you can define a default route.

Code:
routes_enp2s0="192.168.50.1/32
               default gw 192.168.50.1"


That host route is from memory. It's been a long time since I've used it in anger.
It just says to reach 192.168.50.1 send packets out of enp2s0.

The host at 192.168.50.1 needs to know how to deal with packets from/to 172.16.16.0/24, so it will need a route back too.
Are you sure you don't need NAT?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
pgu
l33t
l33t


Joined: 30 Jul 2009
Posts: 721
Location: Oslo, Norway

PostPosted: Sun Mar 31, 2024 10:55 am    Post subject: Reply with quote

Thank you, Yes I do have NAT and I'm using nftables on this host.
It's working and I know how the resulting routing tables should be and how to set them on the command line. My problems are related to how to set up the "net" file to do this in the correct order if I use a static setup. But I will try your notation next time I get access to the machine.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22578

PostPosted: Sun Mar 31, 2024 3:43 pm    Post subject: Reply with quote

If I read your posts correctly, your default route goes through card enp60s0. If so, why are you trying to use the initialization of card enp2s0 to set the default route? I think the configuration would be clearer if you set the default as part of the initialization of the card through which the default-routed traffic will be sent.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum