1

Deployment:

VM -- (eth0)RPI(wlan0) -- Router -- ISP
 ^      ^         ^         ^ 
DHCP  Static     DHCP      GW

NOTE: RPI hostname: gateway

• The goal was to make VMs accessible from the outside the network. Accomplished, according to the tutorial https://www.youtube.com/watch?v=IAa4tI4JrgI, via the Port Forwarding on Router and RPI, by installing dhcpcd and configuring iptables on RPI.

• Here is my interfaces, where I have commented out the auto wlan0, in attempt to fix the issue (before, it was uncommented, and was still the same thing...)

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

#auto wlan0
iface wlan0 inet dhcp
wpa-ssid FunBox-84A8
wpa-psk 7A73FA25C43563523D7ED99A4D

#auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255

• Here is the firewall.conf used by the iptables:

# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*nat
:PREROUTING ACCEPT [86:11520]
:INPUT ACCEPT [64:8940]
:OUTPUT ACCEPT [71:5638]
:POSTROUTING ACCEPT [37:4255]
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 170 -j DNAT --to-destination 192.168.2.83:22
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 171 -j DNAT --to-destination 192.168.2.83:443
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 3389 -j DNAT --to-destination 192.168.2.66:3389
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*filter
:INPUT ACCEPT [3188:209284]
:FORWARD ACCEPT [25:2740]
:OUTPUT ACCEPT [2306:270630]
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*mangle
:PREROUTING ACCEPT [55445:38248798]
:INPUT ACCEPT [3188:209284]
:FORWARD ACCEPT [52257:38039514]
:OUTPUT ACCEPT [2306:270630]
:POSTROUTING ACCEPT [54565:38310208]
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*raw
:PREROUTING ACCEPT [55445:38248798]
:OUTPUT ACCEPT [2306:270630]
COMMIT
# Completed on Sun Feb 17 20:01:56 2019

iptables -L:

pi@gateway:/etc$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination    

• Here is the dhcpcd.conf:

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

denyinterfaces eth0

host Accountant {
hardware ethernet 10:60:4b:68:03:21;
fixed-address 192.168.2.83;
}

host Accountant1 {
hardware ethernet 00:0c:29:35:95:ed;
fixed-address 192.168.2.66;
}
host Accountant3 {
hardware ethernet 30:85:A9:1B:C4:8B;
fixed-address 192.168.2.70;
}

• The error message, that I am not able to figure out:

root@gateway:/home/pi# systemctl restart dhcpcd
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for dhcpcd.service failed because the control process exited with error code.
See "systemctl status dhcpcd.service" and "journalctl -xe" for details.
root@gateway:/home/pi# systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/dhcpcd.service.d
           └─wait.conf
   Active: failed (Result: exit-code) since Sun 2019-02-17 20:36:42 GMT; 6s ago
  Process: 775 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -w (code=exited, status=6)

Feb 17 20:36:42 gateway systemd[1]: Starting dhcpcd on all interfaces...
Feb 17 20:36:42 gateway dhcpcd[775]: Not running dhcpcd because /etc/network/interfaces
Feb 17 20:36:42 gateway dhcpcd[775]: defines some interfaces that will use a
Feb 17 20:36:42 gateway dhcpcd[775]: DHCP client or static address
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Control process exited, code=exited status=6
Feb 17 20:36:42 gateway systemd[1]: Failed to start dhcpcd on all interfaces.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Unit entered failed state.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Failed with result 'exit-code'.
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
root@gateway:/home/pi#               
root@gateway:/home/pi# systemctl daemon-reload
root@gateway:/home/pi# systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/dhcpcd.service.d
           └─wait.conf
   Active: failed (Result: exit-code) since Sun 2019-02-17 20:36:42 GMT; 1min 23s ago

Feb 17 20:36:42 gateway systemd[1]: Starting dhcpcd on all interfaces...
Feb 17 20:36:42 gateway dhcpcd[775]: Not running dhcpcd because /etc/network/interfaces
Feb 17 20:36:42 gateway dhcpcd[775]: defines some interfaces that will use a
Feb 17 20:36:42 gateway dhcpcd[775]: DHCP client or static address
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Control process exited, code=exited status=6
Feb 17 20:36:42 gateway systemd[1]: Failed to start dhcpcd on all interfaces.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Unit entered failed state.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Failed with result 'exit-code'.
root@gateway:/home/pi#       

gateway version:

pi@gateway:/etc$ cat os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian

Questions:

1) What does the error message Not running dhcpcd because /etc/network/interfaces defines some interfaces that will use a DHCP client or static address mean? How to fix it, according to my config above?

2) Why hosts are not getting assigned the IP address according to my dhcpcd.conf, except the host Accountant, which is always getting the same IP, which I want, even if comment out the binding...? How to fix it, in order to be able to bind more than one hosts MAC with IP?

3) What does this notation mean:

#auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255

What are the notation rules for the interfaces file in Linux?

1

Question 1.) Sorry, it looks like you've misunderstood a few things.

dhcpcd is a DHCP client daemon, which is normally started by NetworkManager or ifupdown, not directly by systemd. It is what will be handling the IP address assignment for your wlan0.

You can use dhcpcd as started by systemd if you wish, however that will require disabling all the normal network interface configuration logic (i.e. /etc/network/interfaces must be empty of non-comment lines) of the distribution and replacing it with your own custom scripting wherever necessary. That is for special uses only; if you're not absolutely certain you should do that, you shouldn't.

dhcpcd will never serve IP addresses to any other hosts. This part you added to dhcpcd.conf looks like it would belong to the configuration file of ISC DHCP server daemon, dhcpd (yes it's just one-letter difference) instead:

host Accountant {
hardware ethernet 10:60:4b:68:03:21;
fixed-address 192.168.2.83;
}

host Accountant1 {
hardware ethernet 00:0c:29:35:95:ed;
fixed-address 192.168.2.66;
}
host Accountant3 {
hardware ethernet 30:85:A9:1B:C4:8B;
fixed-address 192.168.2.70;
}

But if you are following the YouTube tutorial you mentioned, you might not even have dhcpd installed, since dnsmasq is supposed to do that job.

As far as I can tell, the equivalent syntax for dnsmasq.conf would be:

dhcp-host=10:60:4b:68:03:21,192.168.2.83,Accountant
dhcp-host=00:0c:29:35:95:ed,192.168.2.66,Accountant1
dhcp-host=30:85:A9:1B:C4:8B,192.168.2.70,Accountant3

Disclaimer: I haven't actually used dnsmasq, so this is based on just quickly Googling its man page.


Question 2.) In the tutorial you mentioned, dnsmasq was supposed to act as a DHCP server on eth0. You did not say anything about it, so I don't know whether it was running or not. If not, the one client that was always getting the same IP might have been simply falling back to a previously-received old DHCP lease that wasn't expired yet. Yes, DHCP clients may store a DHCP lease persistently and keep using it if a network doesn't seem to have a working DHCP server available.


Question 3.): /etc/network/interfaces is a classic Debian/Ubuntu style network interface configuration file. Use man interfaces to see documentation for it, or look here.

In Debian, *Ubuntu, Raspbian etc., NetworkManager will have a plug-in that will read /etc/network/interfaces but won't write to it.

If NetworkManager configuration tools like nmcli, nmtui or GUI-based NetworkManager configuration tools of your desktop environment of choice are used, the configuration would be saved to files in /etc/NetworkManager/system-connections/ directory instead.

If NetworkManager is not installed, the /etc/network/interfaces file is used by the ifupdown package, which includes the commands ifup and ifdown. The package also includes a system start-up script that will run ifup -a on boot, enabling all network interfaces that have auto <interface name> in /etc/network/interfaces. There is also an udev rule which will run ifup <interface name> if a driver for a new network interface gets auto-loaded and /etc/network/interfaces has an allow-hotplug <interface name> line for it.

  • Thanks for explanation, very helpful! It looks like dnsmasq running:pi@gateway:~$ systemctl status dnsmasq ● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2019-02-18 08:59:49 GMT; 4h 53min ago Main PID: 639 (dnsmasq) CGroup: /system.slice/dnsmasq.service └─639 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -r /run/dnsmasq/resolv.conf I have just understood, that it is A lightweight DHCP and caching DNS server – readonly Feb 18 at 13:53
  • So, in this case, I can even uninstall dhcpcd, as it seems doing nothing, since dnsmasq is doing everything?? – readonly Feb 18 at 13:55
  • And, regarding the error message, first Q, do you mean, that I should invoke the dhcpcd in other way than using systemctl start dhcpcd, right? – readonly Feb 18 at 13:56
  • I mean that if you're using /etc/network/interfaces, then either NetworkManager will run dhcpcd for you on wlan0, or you could run ifup wlan0 which will also run dhcpcd for you. If you uncomment auto wlan0 in /etc/network/interfaces, the automatic ifup -a executed by boot scripts will do it; if you add allow-hotplug wlan0, then the udev rules will invoke ifup wlan0 as soon as the driver for it is loaded. – telcoM Feb 18 at 14:03
  • The point is, that, it looks like NetworkManager is not running, at least: pi@gateway:/etc/init.d$ /etc/init.d/network-manager restart -bash: /etc/init.d/network-manager: No such file or directory pi@gateway:/etc/init.d$ /etc/init.d/network-manager status -bash: /etc/init.d/network-manager: No such file or directory – readonly Feb 18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.