22

I upgraded my Raspberry Pi to Jessie, which uses systemd. One side-effect is that it connects using IPv6 only and does not have an IPv4 address. How can I force it to get an IPv4 address from the DHCP server?

One ad-hoc solution is the command

sudo dhclient -4 -v eth0

but this only lasts for the current session.

Greenonline
  • 2,969
  • 5
  • 27
  • 38
John Smith
  • 1,251
  • 3
  • 18
  • 27

8 Answers8

13

Raspbian Jessie no longer has a file called /etc/sysctl.d -- it's now a folder of the same name.

According to the read-me file in the same folder, README.sysctl, it basically says that any .conf file will be read in at boot time and processed. Any legal file name will work, but they suggested local.conf, so that's what I used.

I created /etc/sysctl.d/local.conf and added the single line from the other answers:

net.ipv6.conf.all.disable_ipv6=1

This appears to work just fine.

Jim
  • 402
  • 6
  • 11
7

sudo nano /etc/sysctl.conf

append the following lines to turn off ipv6:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

run sudo sysctl -p to take effect or just reboot.

AlexOnLinux
  • 417
  • 3
  • 5
3

In Raspbian Jessie/Jessie Lite, simply edit the /etc/sysctl.conf file and add the switch to disable ipv6, as follows:

sudo nano /etc/sysctl.conf

Enter the text:

net.ipv6.conf.all.disable_ipv6=1

Save the file with Ctrl-O, Ctrl-X and reboot the RPi.

Jacobm001
  • 11,904
  • 7
  • 47
  • 58
guitarpicva
  • 155
  • 5
2

you can insert a line into sysctl to disable ipv6.

echo net.ipv6.conf.all.disable_ipv6=1 >> /etc/sysctl.conf

this will work after next reboot.

natevw
  • 113
  • 5
Joe Platano
  • 852
  • 8
  • 19
1

the easiest way I found to also get an IPv4 address for the interface was changing /etc/network/interfaces: setting the manual to dhcp ... that also gets you an IPv4 address on eth0 ... probably only a hack but haven't found anything better yet either ...

    auto eth0
    allow-hotplug eth0
    # iface eth0 inet manual
    iface eth0 inet dhcp
Ghosty
  • 11
  • 1
1

Combining, correcting and adding to the previous answers:

To fix an interface (either eth or wlan) that is showing just an inet6 (IPV6) address and no inet (IPV4) address, you can append a config file to disable inet6 (IPV6) assignment, so that all interfaces are given an inet (IPV4) address. If that config file is then deleted again, interfaces will then be given BOTH an inet (IPV4) and an inet6 (IPV6) address, i.e. a return to the usual default state.

To add the file:

sudo nano /etc/sysctl.d/local.conf

and add the single line:

net.ipv6.conf.all.disable_ipv6=1

Save with Ctrl-O, Y, [Return]. Reboot and login again.

sudo reboot

Check the addresses using

ifconfig

Remove the config file and reboot:

cd /etc/sysctl.d
sudo rm local.conf
sudo reboot

Check again with ifconfig:

ifconfig

See both inet (IPV4) and inet6 (IPV6) addresses for all interfaces:

eth0      Link encap:Ethernet  HWaddr 00:e0:4c:53:44:58
          inet addr:192.168.1.228  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::26a5:b629:f948:92c3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:62:b4:7a
          inet addr:192.168.1.229  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::254c:3f61:fdc:bc49/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

And I can once again SSH to my Pi Zero using either eth0 or wlan0, both using either IPV4 or IPV6 address.

Autumn Skye
  • 105
  • 3
1

I upgraded my Raspberry Pi to Stretch and I was unable to have any success with any variation of the net.ipv6.conf.all.disable_ipv6=1 answers.

Manually running sudo dhclient -4 -v eth0 to get my network/internet connectivity back worked, however as stated by the original poster it does not survive a reboot.

I noticed that sudo ifup -v eth0 called dhclient, but it was failing and instead of functioning correctly, it was showing the usage information for the dhclient command.

The workaround appears to be to move away from dhclient and instead install isc-dhcp-client. Upon reboot my connectivity was automatically available after installing this package.

sudo apt-get install isc-dhcp-client
sudo reboot
mrswadge
  • 111
  • 3
0

I have the same problem and tried the solution below, this works fine after rebooting my Pi.

sudo nano  /etc/sysctl.d/98-rpi.conf

type

net.ipv6.conf.all.disable_ipv6=1

Type Ctrl-X then answer "Y" followed by to save the file.

sudo reboot

Now I see my ip4 address on booted screen.

guitarpicva
  • 155
  • 5