pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20230205-masq_of_the_dhcphantasm.md (2070B)


      1 The other day I wanted to test a new network device without connecting it to my home LAN.  I knew the device was preconfigured to use DHCP so I very quickly set up one of my laptops as a DHCP server using [dnsmasq](https://dnsmasq.org/){target="_blank" rel="noreferrer"}.
      2 
      3 After making sure the `dnsmasq` package was installed on the laptop I disconnected it from the WiFi and plugged it into a switch.
      4 
      5 Configuring a static IP differs from system to system, but in this case I was using `netctl`.  I took a copy of the example configuration file, /etc/netctl/examples/ethernet-static, put it into the /etc/netctl directory, and changed the 'Interface' and 'Address' variables
      6 ```
      7 Description='A basic static ethernet connection'
      8 Interface=enp0s25
      9 Connection=ethernet
     10 IP=static
     11 Address=('192.168.1.1/24')
     12 #Routes=('192.168.0.0/24 via 192.168.1.2')
     13 Gateway='192.168.1.1'
     14 DNS=('192.168.1.1')
     15 
     16 ## For IPv6 autoconfiguration
     17 #IP6=stateless
     18 
     19 ## For IPv6 static address configuration
     20 #IP6=static
     21 #Address6=('1234:5678:9abc:def::1/64' '1234:3456::123/96')
     22 #Routes6=('abcd::1234')
     23 #Gateway6='1234:0:123::abcd'
     24 ```
     25 
     26 Bringing the interface up with
     27 ```
     28 sudo netctl start ethernet-static
     29 ```
     30 
     31 The dnsmasq configuration file is usually /etc/dnsmasq.conf, or you can drop your own config files into /etc/dnsmasq.d/ (ensure you uncomment the include line in /etc/dnsmasq.conf).
     32 
     33 My setup was very simple
     34 ```
     35 # specify ethernet device to operate on
     36 interface=enp0s25
     37 
     38 # disable dns
     39 port=0
     40 
     41 # configure dhcp range and lease time
     42 dhcp-range=192.168.1.10,192.168.1.12,8h
     43 ```
     44 
     45 I didn't need to set a netmask as I am putting the DHCP server (my laptop) in the same range.  Before starting `dnsmasq` it is a good idea to validate the configuration
     46 ```
     47 dnsmasq --test
     48 ```
     49 
     50 After starting the `dnsmasq` service I could plug my network device into the router and monitor for any assigned IPs in the file /var/lib/misc/dnsmasq.leases.
     51 
     52 There is much more you can do with `dnsmasq` if you want to use it for DHCP properly, but this shows how quick it can be to run it on a LAN or lab environment.