Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
error setting static route [solved]
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
snIP3r
l33t
l33t


Joined: 21 May 2004
Posts: 818
Location: germany

PostPosted: Fri Nov 23, 2018 10:34 am    Post subject: error setting static route [solved] Reply with quote

hi all!

i have an error setting a static route on my gentoo testmachine. first interface enp1s0 is connected to the "normal" network 192.168.0.0/24 and the second to my "testnetwork" 192.168.1.1/24 with a dnsmasq dhcp.
my config looks like this:

Code:

config_enp1s0="192.168.0.25 netmask 255.255.255.0"
routes_enp1s0="default via 192.168.0.5"
dns_servers_enp1s0="192.168.0.5"

config_enp2s0="192.168.1.1 netmask 255.255.255.0"
routes_enp2s0="default via 192.168.0.25"


but on boot/reboot, the second interface does not start. if restarting it manually i get this:

Code:

/etc/init.d/net.enp2s0 restart
 * Bringing up interface enp2s0
 *   192.168.1.1 ...                                                                                  [ ok ]
 *   Adding routes
 *     default via 192.168.0.25 ...
Error: Nexthop has invalid gateway.                                                                   [ !! ]


but then the interface is up and running:

Code:

 ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.25  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::4770:d116:30e5:bf2  prefixlen 64  scopeid 0x20<link>
        ether 00:25:22:44:47:b5  txqueuelen 1000  (Ethernet)
        RX packets 403  bytes 37234 (36.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 486  bytes 117148 (114.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.1.1  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 00:08:54:56:60:83  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


i have no idea what else to configure. packet forwarding is on
Code:

net.ipv4.ip_forward = 1


any ideas?

thx in advance
snIP3r
_________________
Intel i3-4130T on ASUS P9D-X
Gentoo Base System 2.2
Kernel 4.19.23-gentoo SMP
-----------------------------------------------
if your problem is fixed please add something like [solved] to the topic!


Last edited by snIP3r on Mon Nov 26, 2018 1:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
mike155
l33t
l33t


Joined: 17 Sep 2010
Posts: 997
Location: Frankfurt, Germany

PostPosted: Fri Nov 23, 2018 1:06 pm    Post subject: Reply with quote

You cannot set two default routes. Please note that IPv4 standard routing rules (the routes you manage with 'route') are NOT attached to specific interfaces. There is a global routing table, and you can define only one default route.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Fri Nov 23, 2018 6:28 pm    Post subject: Reply with quote

snIP3r,

Code:
$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         router          0.0.0.0         UG    2      0        0 eth0
loopback        0.0.0.0         255.0.0.0       U     0      0        0 lo
loopback        localhost       255.0.0.0       UG    0      0        0 lo
192.168.100.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
the kernel matches outgoing packets against the routing table entries from the bottom, working its way up.

At the bottom, it says to reach 192.168.100.0/24 no gateway is required, just send the packet out of eth0.
Lets ignore loopback.
Any packets that reach the default are sent to a gateway called router that is reached via eth0.
Were there more routes, further up the routing table, the could not be reached. Default matches everything.

Code:
config_enp2s0="192.168.1.1 netmask 255.255.255.0"
routes_enp2s0="default via 192.168.0.25"

enp2s0 is in the 192.168.1.0/24 subnet. It cannot reach 192.168.0.25 so its not useful to try to define a static route there out of enp2s0.
If the route had been created and used, you wouldn't like the result.
_________________
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
snIP3r
l33t
l33t


Joined: 21 May 2004
Posts: 818
Location: germany

PostPosted: Mon Nov 26, 2018 1:27 pm    Post subject: Reply with quote

thx for the explanation!
i totally forgot to do some iptables magic to do the job:

Code:

iptables -A POSTROUTING -s 192.168.1.0/24 -o enp1s0 -j MASQUERADE


and everything is ok now...
_________________
Intel i3-4130T on ASUS P9D-X
Gentoo Base System 2.2
Kernel 4.19.23-gentoo SMP
-----------------------------------------------
if your problem is fixed please add something like [solved] to the topic!
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