|  About Me  |  Blogs  |  Photos  |  Publications  |  Resume  | 

Network interface script to enable dhcp interface for dnsmasq

My wireless interface have many profiles, some profiles run as dhcp client while others run as dhcp server. This means I have to setup my dhcp server (I use dnsmasq) to listen on the interface when the profile that acts as dhcp server is brought up, and remove that interface when the profile is brought down.

For debian this can be done in the network interfaces script like this:

iface peernet inet static
        hostname frasco
        wireless_essid peernet
        wireless_key off
        wireless_mode ad-hoc
        address 192.168.0.1
        netmask 255.255.255.0
        # iptables maquerade
         pre-up iptables -t nat -A POSTROUTING -o $IFACE -j MASQUERADE
         post-down iptables -t nat -D POSTROUTING -o $IFACE -j MASQUERADE
        # dhcp script
        up echo -e "interface=$IFACE #ADD:$IFACE\ndhcp-range=192.168.0.10,192.168.0.50,12h #ADD:$IFACE" >> /etc/dnsmasq.conf
        up /etc/init.d/dnsmasq restart
        down /bin/sed -ie "/#ADD:$IFACE/d" /etc/dnsmasq.conf
        down /etc/init.d/dnsmasq restart

When I bring up this profile, i.e., ifup eth1=peernet, it addes eth1 interfaces to dnsmasq.conf so it listens on that interface for dhcp request and assigns them IP ranges from 192.168.0.10 to 192.168.0.50. When the profile is brought up, i.e., ifdown eth1, the interface is removed from dnsmasq.

This needs to be done for all the profiles that runs dhcp server.

Leave a Reply

You must be logged in to post a comment.