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.

2
  • None of the answers below worked for me, instead I needed to sudo apt-get install isc-dhcp-client after using sudo dhclient -4 -v eth0 to get online.
    – mrswadge
    May 20, 2019 at 23:12
  • Some further context to my previous comment. In my situation the symptoms when running sudo ifup -v eth0 the call to dhclient was failing and instead showing the usage information.
    – mrswadge
    May 21, 2019 at 8:21

8 Answers 8

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.

2
  • Anything .d in /etc was never anything but a directory to start with. I dunno if Joe Platano's answer involves a typo or whether that will actually work, somehow I doubt it (although there seems to be another answer confirming it will).
    – goldilocks
    Dec 7, 2016 at 14:39
  • For me this served only to kill the ipv6 without creating an ipv4 instead after reboot. Dec 21, 2023 at 12:20
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.

1
  • Confirmed working on Raspbian Buster. Apr 12, 2020 at 5:51
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.

1
  • @AlexOnLinux answer is better ^^^^ Sep 23, 2021 at 19:06
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.

1
  • 2
    It's /etc/sysctl.conf as target file. Be aware that the > will override the entire file!
    – David
    Dec 2, 2019 at 16:00
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
1
  • Raspbian Jessie does not use dhcp (unless the user has really fiddled with it) and this would prevent GUI WiFi support from working.
    – Milliways
    Nov 6, 2015 at 11:51
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.

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
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.

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