View previous topic :: View next topic |
Author |
Message |
snIP3r l33t
Joined: 21 May 2004 Posts: 853 Location: germany
|
Posted: Fri Nov 23, 2018 10:34 am Post subject: error setting static route [solved] |
|
|
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
Kernel 5.15.88-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 |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Fri Nov 23, 2018 1:06 pm Post subject: |
|
|
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 |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54214 Location: 56N 3W
|
Posted: Fri Nov 23, 2018 6:28 pm Post subject: |
|
|
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 |
|
|
snIP3r l33t
Joined: 21 May 2004 Posts: 853 Location: germany
|
Posted: Mon Nov 26, 2018 1:27 pm Post subject: |
|
|
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
Kernel 5.15.88-gentoo SMP
-----------------------------------------------
if your problem is fixed please add something like [solved] to the topic! |
|
Back to top |
|
|
|