4

I am trying to configure my eth0 interface with a static ip through my dhcp server. The static assignment is working fine, but I can't access the external network because there's no default gateway.

pi@raspberry:~ $ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.30.0       0.0.0.0         255.255.255.0   U     202    0        0 eth0

If I run sudo dhclient or route add default gw 10.0.30.1 the default route is added and I can hit WAN no problem. But every time I restart the pi it loses this setting. How do I make this stay?

Here's my /etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

I looked at

Can't make change to "route" stick and "connect: Network is unreachable" on a working (connected) wlan0 interface and Static local IP/gateway config on startup issues but I didn't see a solution.

EDIT: Adding /etc/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.
#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.
# Some interface drivers reset when changing the MTU so disabled by default.
#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

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

interface eth0
inform 10.0.30.14
static routers=10.0.30.1
static domain_name_servers=8.8.8.8
static domain_search=8.8.8.4

EDIT 2: Adding ifconfig output

eth0      Link encap:Ethernet  HWaddr b8:27:eb:b1:50:55
      inet addr:10.0.30.14  Bcast:10.0.30.255  Mask:255.255.255.0
      inet6 addr: fe80::ba27:ebff:feb1:5055/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:1590 errors:0 dropped:0 overruns:0 frame:0
      TX packets:361 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:179536 (175.3 KiB)  TX bytes:56354 (55.0 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)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:e4:05:00
      inet addr:169.254.127.199  Bcast:169.254.255.255  Mask:255.255.0.0
      inet6 addr: fe80::d8fc:4221:1b8d:c2c2/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:0 (0.0 B)  TX bytes:27244 (26.6 KiB)
8
  • If you include dhcp in /etc/network/interfaces this prevents dhcpcd from running. I continue to wonder WHY people fiddle with these files.
    – Milliways
    Mar 18 '16 at 9:29
  • Perhaps you need to ask for details of gateways from the dhcp server, that does not appear amongst: # A list of options to request from the DHCP server. - mind you I think rain is wet so who am I to say...! 8-P
    – SlySven
    Mar 18 '16 at 16:46
  • @Milliways Can you clarify what I should be doing then? I wouldn't have touched the files if the configuration had worked. Mar 18 '16 at 16:54
  • @SlySven I'm not sure what you're getting at. Is there a missing option in the dhcpcd file? Mar 18 '16 at 16:55
  • I don't know but that did strike me as a possibility - is it a fundamental role of a DHCP server to tell hosts it assigns IPv4 addresses for: "here is the gateway addresses to use" - or is it something they have to ask for? I suspect the fine manuals might say, but I'm looking now... Ah ha that line static routers=10.0.30.1 on the RPi in your first Edit - is that overriding anything your dchp server is telling you?
    – SlySven
    Mar 18 '16 at 17:36
1

I managed to solve this by returning everything to defaults including /etc/dhcpcd.conf

Specifically once I removed these lines the default route appeared on boot

interface eth0
inform 10.0.30.14
static routers=10.0.30.1
static domain_name_servers=8.8.8.8
static domain_search=8.8.8.4
0

Do you have the following lines in your /etc/dhcpcd.conf file:

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes

Especially the option classless_static_routes line.

You shouldn't have to but you may have to hard-code the default gateway by adding the following to the interface in /etc/network/interfaces:

iface wlan0 inet dhcp
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    post-up route add default gw 192.168.1.254 eth0
    pre-down route del default gw 192.168.1.254 eth0
1
  • I do see those options. I tried adding post-up route add default gw 10.0.30.1 eth0 under the iface eth0 inet dhcp line, no joy. Mar 18 '16 at 1:39
0

I did a change in "/etc/network/interfaces" and it works

iface eth0 inet static
address 192.168.1.111
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 10.0.30.1        --> edit to your IP Gateway

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