dnsmasq startup script start-dnsmasq.sh fails to detect IP address on machine running Ubuntu 17.10 using DHCP.
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ docker-compose up
Creating dnsmasq ... done
Creating nginx ... done
Creating sniproxy ... done
Attaching to nginx, sniproxy, dnsmasq
dnsmasq | sh: 100: unknown operand
dnsmasq | Could not autodetect host IP. Exiting.
sniproxy exited with code 1
dnsmasq exited with code 1
Running the part of the script that pulls the host IP address from the system in chunks on Ubuntu 16.04 not using DHCP looks like this:
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp0s25
default via 192.168.1.1 onlink
192.168.1.0/24 proto kernel scope link src 192.168.1.18
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp0s25 | grep -w "link"
192.168.1.0/24 proto kernel scope link src 192.168.1.18
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp0s25 | grep -w "link" | awk -F " " '{print $NF}'
192.168.1.18
Running the same thing on Ubuntu 17.10 using DHCP looks like this:
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp5s0
default via 192.168.1.1 proto dhcp src 192.168.1.18 metric 100
192.168.1.0/24 proto kernel scope link src 192.168.1.18
192.168.1.1 proto dhcp scope link src 192.168.1.18 metric 100
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp0s25 | grep -w "link"
192.168.1.0/24 proto kernel scope link src 192.168.1.18
192.168.1.1 proto dhcp scope link src 192.168.1.18 metric 100
user@ubuntu:~/lan-cache-docker/docker-dnsmasq$ ip route show dev enp0s25 | grep -w "link" | awk -F " " '{print $NF}'
192.168.1.18
100
The 100 at the end is being appended to HOST_IP which causes the error. I'm not sure what's causing the extra information; if it's the distro version, a different version of the ip tool, if it's DHCP related, or something else.
Recommend changing the regex used in grep to explicitly match an IP address:
grep -Pom1 'link\s+src\s+\d+\.\d+\.\d+\.\d+'
The above will use a perl regular expression, returning only what's matched, and only one match. This will match on the first IP address found in the response from ip route following the text link src.
dnsmasq startup script start-dnsmasq.sh fails to detect IP address on machine running Ubuntu 17.10 using DHCP.
Running the part of the script that pulls the host IP address from the system in chunks on Ubuntu 16.04 not using DHCP looks like this:
Running the same thing on Ubuntu 17.10 using DHCP looks like this:
The 100 at the end is being appended to HOST_IP which causes the error. I'm not sure what's causing the extra information; if it's the distro version, a different version of the
ip
tool, if it's DHCP related, or something else.Recommend changing the regex used in grep to explicitly match an IP address:
grep -Pom1 'link\s+src\s+\d+\.\d+\.\d+\.\d+'
The above will use a perl regular expression, returning only what's matched, and only one match. This will match on the first IP address found in the response fromip route
following the textlink src
.