DHCP server with multiple interfaces on ubuntu, destroys default gateway
Solution 1
I'm hardly any kind of expert on this subject, but I suspect that because of the broadcast nature of DHCP packets, your local DHCP server is always going to answer locally originating requests regardless of the listening interfaces that you configured.
So I would suggest you try simply setting "reject" statements in your dhclient.conf to reject offers from the local server:
reject 10.0.1.1;
reject 10.0.2.1;
(I'm only guessing that you can use multiple reject statements, man page is unclear.)
I can think of some other things to try also, but I might be wrong in my initial assumption anyway. I always find this a useful tool to diagnose what is happening:
apt-get install dhcpdump
dhcpdump -i eth1
PS: If you want to keep eth0, eth1, eth2 etc. properly separated, consider using VLANs to isolate traffic at layer 2.
Solution 2
You should only have one default gateway on your computer. And it should go to a router that going toward the border or out of your network. You could always use ip route list
to see which routers you have.
So there are actually two errors in each of your eth1
and eht2
stanza in /e/n/interfaces
.
- You should not have a
gateway
directive pointing at itself. If your machine doesn't know where to send a packet with an unknownIP
-address, why should you tell it to forward that packet to itself? So you should never point agateway
to itself. - You should only have one (or none) default gateway in your machine. And that should point outside. The interface to the outside is on
eth0
, and that is getting the gatway fromdhcp
. So no need to setgateway
here.
So, remove all gateway
dirctives from /e/n/interfaces
and it will work (better).
And by the way, both network
and broadcast
are calculated from address
and netmask
, so you don't need to specify them. It actually can create some strange errors if you get them wrong, so you are better of not specify them. See https://askubuntu.com/a/432876/9993
To your clients in your LAN that you have your own dhcp server on, you should tell them to use your machine in the configuration for the dhcp server. So on eth1
you should tell the clients to use 10.0.1.1
as router. You can't do that in /e/n/interfaces
.
Related videos on Youtube
Henrik Alstad
Updated on September 18, 2022Comments
-
Henrik Alstad over 1 year
I use Ubuntu, and I have many interfaces.
eth0
, which is my internet connection, and it gets its info from a DHCP-server totally outside of my control.I then have
eth1
,eth2
,eth3
andeth4
which I have created a DHCP-server for.(ISC DHCP-Server)It seems to work, and I even get an IP-address from the foreign DHCP-server on the internet facing interface.
However, for some reason it seems my gateway for
eth0
became screwed after I installed my local DHCP-server foreth1
-eth4
. (I think so because I got an IP foreth0
, and I can ping other stuff on the local network, but I cannot get access to the internet).My
eth0
-specific info in/etc/network/interfaces
:auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet static address 10.0.1.1 netmask 255.255.255.0 network 10.0.1.0 broadcast 10.0.1.255 gateway 10.0.1.1 mtu 8192 auto eth2 iface eth2 inet static address 10.0.2.1 netmask 255.255.255.0 network 10.0.2.0 broadcast 10.0.2.255 gateway 10.0.2.1 mtu 8192
My
/etc/default/isc-dhcp-server
:INTERFACES="eth1 eth2 eth3 eth4"
So why does my local DHCP-server mess up the gateway for
eth0
, when I tell it not to listen toeth0
? Anyone see the problem or what I can do to fix it?The problem seems indeed to be the gateways.
netstat -nr
gives:0.0.0.0 --- 10.X.X.X ---- 0.0.0.0 --- UG 0 0 0 eth3
It should have been
0.0.0.0 129.2XX.X.X 0.0.0.0 UG 0 0 0 eth0
So for some reason, my local DHCP-server overrides the gateway I get from the network DHCP.
Edit:
dhcp.conf
looks like this(I included info only foreth1
subnet):ddns-update-style none; not authoritative; subnet 10.0.1.0 netmask 255.255.255.0 { interface eth1; option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 600; max-lease-time 7200; range 10.0.1.10 10.0.1.100; host camera1_1 { hardware ethernet 00:30:53:11:24:6E; fixed-address 10.0.1.10; } host camera2_1 { hardware ethernet 00:30:53:10:16:70; fixed-address 10.0.1.11; } }
Also, it seems that the gateway is correctly set if I run
/etc/init.d/networking restart
in a terminal, but that's not helpful for me, I need the correct gateway to be set during startup, and I'd rather find the source of the problem-
Javier Rivera over 11 yearsThere is no such thing as a default gateway for eth0, default gateways are system-wide. Can you post your dhcp configuration file?.
-
Henrik Alstad over 11 yearsAdded it now. I only added part of the file(Only one subnet for eth1)..the other are pretty much the same
-
Anders over 9 yearsThere are such thing as a default gateway in a machine, and it should only be one. You set up three here with the
gateway
directives anddhcp
(what abouteth3
andeth4
? Do you also set them up likeeth1
and `eth2). See my answer. -
Anders over 9 yearsIt was a long time I set up an
dhcp
server, so I might be wrong, but I think that you have to tell the machines in each subnet which router (gatway) they should use. I do not see any shuch specification in your example.
-
-
Anders over 9 yearsVLAN is usually better if you want to have many LAN on the same switch/interface. If you want to have them separated on different devices it is probably better to set up a firewall in this router.