A Linux Playground

My doodles and what I get up to.

Secondary IP Address on Raspberry Pi

Testing a ngix proxy to a transmission server I found that the server was dening the connection. This is strange as the proxy server is only allowed IP address to connect to the transmission server.

I began investigating the rasperry pi and it had to correct ip address.

ifconfig shows that the device has the correct ip address and ngix is reachable from that address.

1
ifconfig -a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
eth0      Link encap:Ethernet  HWaddr b8:27:eb:bb:95:b0
          inet addr:192.168.0.201  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:febb:95b0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1497 errors:0 dropped:0 overruns:0 frame:0
          TX packets:712 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:93269 (91.0 KiB)  TX bytes:89513 (87.4 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Next I checked the interfaces file and it also showed the correct configuration

1
cat /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
# Please note that this file is written to be used with dhcpcd.
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 192.168.0.201
  gateway 192.168.0.1
  netmask 255.255.255.0
1
ip a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:bb:95:b0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.201/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.0.30/24 brd 192.168.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:febb:95b0/64 scope link
       valid_lft forever preferred_lft forever

This is very strange it shows that the ethernet interface is gaining a second IP address that I have not set. Doing some web searches I find that the device has a dhcp deamon that runs automatically and adds this second IP address from my dhcp server.

To resolve the problem I choose to disable the dhcp service on the device.

1
sudo systemctl disable dhcpcd.service

Alternatively I could force the nginx server to only bind to the 192.168.0.201 address however this would mean changing the IP address in multiple places if I ever need to modify the server IP address.