Use dnsmasq to pushing routes to my clients on a small local network

7,517

AFAICT

Unfortunately providing several dhcp-options to dnsmasq results in the last being applied (not all).

So, you need to supply only two IP addresses (network and gateway):

dhcp-option=121,10.0.4.0/24,10.8.0.1

And, you also need to tell each server[123] to ask for the route.

And, if your ISC DHCP client doesn’t have support for this option (one in current Debian does), you need a line like below in /etc/dhclient.conf or /etc/dhcp3/dhclient.conf:

option classless-static-routes code 121 = array of { ip-address, ip-address };

to make dhclient aware of the 121 option and then use some script in /etc/dhcp3/dhclient-exit-hooks.d/configure_static_routes to make the network configuration automatic.

This is quite a good description.

Share:
7,517

Related videos on Youtube

Eduardo Lucio
Author by

Eduardo Lucio

Free software enthusiast. I love working with hardware virtualization mainly Xen (hypervisor) and with a free source general programming purpose editor/IDE called Vim. I working with software development (open source) and as an IT manager. I have a daughter and live in Brazil (Brasília).

Updated on September 18, 2022

Comments

  • Eduardo Lucio
    Eduardo Lucio over 1 year

    I'm trying to use dnsmasq to pushing routes to my clients on a small local network.

    However my clients (Server #1, #2 and #3) can not use these routes. The dnsmasq service is running and I do not know what may be going wrong.

    This is the content of my "/etc/dnsmasq.conf" file:

    domain-needed
    bogus-priv
    no-resolv
    no-poll
    server=/localnet/192.168.56.254
    server=8.8.3.3
    server=8.8.8.8
    server=208.67.220.220
    local=/brlightinternet.local/
    interface=vboxnet0
    listen-address=192.168.56.254
    no-hosts
    expand-hosts
    domain=brlightinternet.local
    dhcp-range=192.168.56.3,192.168.56.253,12h
    dhcp-option=option:router,192.168.56.254
    
    # pushing routes
    dhcp-option=121,10.0.4.0/24,10.0.6.4,10.8.0.0/24,10.0.6.4,10.0.6.0/24,10.8.0.1
    dhcp-option=249,10.0.4.0/24,10.0.6.4,10.8.0.0/24,10.0.6.4,10.0.6.0/24,10.8.0.1
    
    dhcp-option=vendor:MSFT,2,1i
    cache-size=150
    

    IMPORTANT: "192.168.56.254" is not the ip of the server running dnsmasq. Its ip is "192.168.56.1". From what I understand we can assign a different ip to dnsmasq.

    This is the network configuration ("/etc/sysconfig/network-scripts/ifcfg-enp0s17") on each client (Server #1, #2 and #3)...

    BOOTPROTO=static
    DEVICE=enp0s17
    DNS1=192.168.56.254
    GATEWAY=192.168.56.254
    IPADDR=192.168.56.120
    IPV6INIT=NO
    NETMASK=255.255.255.0
    NM_CONTROLLED=yes
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=NO
    ZONE=public
    

    ... only the ips change...

    Server #1 -> IPADDR=192.168.56.122
    Server #2 -> IPADDR=192.168.56.120
    Server #3 -> IPADDR=192.168.56.121
    

    Information about the LANs of each server...

    Server #1

    [root@localhost ~]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 08:00:12:26:e2:6c brd ff:ff:ff:ff:ff:ff
        inet 192.168.56.122/24 brd 192.168.56.255 scope global noprefixroute enp0s17
           valid_lft forever preferred_lft forever
        inet6 fe80::a00:12ff:fe26:e26c/64 scope link 
           valid_lft forever preferred_lft forever
    

    Server #2

    [root@localhost ~]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 08:00:27:2c:d1:58 brd ff:ff:ff:ff:ff:ff
        inet 10.0.2.10/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s8
           valid_lft 888sec preferred_lft 888sec
        inet6 fe80::2c5c:27aa:2636:8dc9/64 scope link noprefixroute 
           valid_lft forever preferred_lft forever
    3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 08:00:1c:a6:b9:59 brd ff:ff:ff:ff:ff:ff
        inet 192.168.56.120/24 brd 192.168.56.255 scope global noprefixroute enp0s17
           valid_lft forever preferred_lft forever
        inet6 fe80::a00:1cff:fea6:b959/64 scope link 
           valid_lft forever preferred_lft forever
    5: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
        link/none 
        inet 10.8.0.1/24 brd 10.8.0.255 scope global tun0
           valid_lft forever preferred_lft forever
        inet6 fe80::6a67:7379:b64:967c/64 scope link flags 800 
           valid_lft forever preferred_lft forever
    

    Server #3

    [root@localhost ~]# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 08:00:27:71:77:07 brd ff:ff:ff:ff:ff:ff
        inet 10.0.4.4/24 brd 10.0.4.255 scope global noprefixroute dynamic enp0s8
           valid_lft 1115sec preferred_lft 1115sec
        inet6 fe80::899f:8ca4:a7c6:25a7/64 scope link noprefixroute 
           valid_lft forever preferred_lft forever
    3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 08:00:ea:4e:40:ae brd ff:ff:ff:ff:ff:ff
        inet 192.168.56.121/24 brd 192.168.56.255 scope global noprefixroute enp0s17
           valid_lft forever preferred_lft forever
        inet6 fe80::a00:eaff:fe4e:40ae/64 scope link 
           valid_lft forever preferred_lft forever
    4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
        link/none 
        inet 10.8.0.6/24 brd 10.8.0.255 scope global tun0
           valid_lft forever preferred_lft forever
        inet6 fe80::48c2:b3cd:5845:5d35/64 scope link flags 800 
           valid_lft forever preferred_lft forever
    

    NOTE I: "ip_forward" is enabled on Server #2...

    echo -n "net.ipv4.ip_forward=1
    
    " >> /etc/sysctl.d/ip_forward.conf
    sysctl -w net.ipv4.ip_forward=1
    


    NOTE II: This thread is entirely related to the problem...

    Use the LANs of one server to access the LAN of another

    With this solution I can make routes without problems...

    https://unix.stackexchange.com/a/457347/61742

    ... but without the benefit of having the thing centralized as when I use dnsmasq.


    Thanks! =D

  • Eduardo Lucio
    Eduardo Lucio almost 6 years
    @slm Please take a look at this thread: unix.stackexchange.com/q/459945/61742 .