I was troubleshooting a dnsmasq DHCP server back in few days and notice special settings have to be applied if the particular dnsmasq DHCP server is configured to serve multiple subnet.
In my scenario, the DHCP server is having one nic, eth0. For some reason, there are 2 subnets being served, 192.168.0.0/24 and 192.168.1.0/24. The eth0 is configured as 192.168.0.1/24 while an additional ip 192.168.1.1 is added to eth0 too.
So DHCP clients that connect to the eth0 of DHCP server (through switches) could retrieve IP from same subnet without any issue, however it seems like the DHCP gateway of the 2nd subnet is acting weird. For example, here is the DHCP lease file i got from one of the DHCP client.
# cat /var/lib/dhcp/pump.lease
Device eth0
IP: 192.168.1.10
Netmask: 255.255.255.0
Broadcast: 192.168.1.255
Network: 192.168.1.0
Boot server 192.168.1.1
Next server 192.168.1.1
Gateways: 192.168.0.1
Hostname: test-dhcp-client
Domain: test.internal
Renewal time: Fri Nov 23 17:38:13 2012
Expiration time: Fri Nov 23 19:08:13 2012
Interestingly, this DHCP client is assigned with the 2nd DHCP subnet (i.e. 192.168.1.0/24) however gateway of default subnet (192.168.0.0/24) is being assigned.
To fix this, I tried couples of approach but eventually it looks like configuring the option though dhcp-range tagging would do the best. Below are the configuration snippet that fixed the problem.
listen-address=192.168.0.1
listen-address=192.168.1.1
dhcp-range=set:1stblock,192.168.1.10,192.168.0.50,255.255.255.0
dhcp-range=set:2ndblock,192.168.1.1,192.168.1.50,255.255.255.0
dhcp-option=tag:1stblock,option:router,192.168.0.1
dhcp-option=tag:2ndblock,option:router,192.168.1.1
So in above example, I assign a tag to each individual subnet (i.e 1stblock -> 192.168.0.0/24, 2ndblock -> 192.168.1.0/24) and then assign individual router ip with each associated tag.
I am a Linux Administrator in Hong Kong, specialized in RHEL administration as well as IAAS cloud deployment. :-)
2012年11月23日 星期五
2012年3月28日 星期三
Tricks to avoid DHCP client to override /etc/resolv.conf
I have a laptop installed with Ubuntu and is using DHCP client to connect to the Internet in couples of locations. Most of the DHCP server love to offer DHCP IP bundled with DNS addresses which is kind of convenience if one dont have their own DNS. For some reason, I have to use my own DNS server to perform DNS lookup and this DHCP kindness is getting annoying as I have to update the resolv.conf everytime I got the DHCP IP.
Just think of a trick to lock the /etc/resolv.conf from overwriting by doing chattr +i, i.e.
[root@ ~]# lsattr /etc/resolv.conf
------------- /etc/resolv.conf
[root@ ~]# chattr +i /etc/resolv.conf
[root@ ~]# lsattr /etc/resolv.conf
----i-------- /etc/resolv.conf
After that the file /etc/resolv.conf would be locked from writing until removal of this tag. I tested it by appending some crap to the /etc/resolv.conf but it doesnt allow me to write over.
[root@ ~]# echo some-crap >> /etc/resolv.conf
-bash: /etc/resolv.conf: Permission denied
Now I could keep using my own DNS and no need to update the file all the time.
Falling back is easy.
[root@ ~]# chattr -i /etc/resolv.conf
[root@ ~]# lsattr /etc/resolv.conf
------------- /etc/resolv.conf
Just think of a trick to lock the /etc/resolv.conf from overwriting by doing chattr +i, i.e.
[root@ ~]# lsattr /etc/resolv.conf
------------- /etc/resolv.conf
[root@ ~]# chattr +i /etc/resolv.conf
[root@ ~]# lsattr /etc/resolv.conf
----i-------- /etc/resolv.conf
After that the file /etc/resolv.conf would be locked from writing until removal of this tag. I tested it by appending some crap to the /etc/resolv.conf but it doesnt allow me to write over.
[root@ ~]# echo some-crap >> /etc/resolv.conf
-bash: /etc/resolv.conf: Permission denied
Now I could keep using my own DNS and no need to update the file all the time.
Falling back is easy.
[root@ ~]# chattr -i /etc/resolv.conf
[root@ ~]# lsattr /etc/resolv.conf
------------- /etc/resolv.conf
訂閱:
文章 (Atom)