1

I've seen similar questions on here but I'm still having issues setting up the DHCP server. I am trying to connect directly via ethernet to a Raspberry Pi to SSH into from my laptop running the WSL. I have the Pi configured for the local ip address 10.0.0.45 which works on my home network. I tried to set it up on my laptop to act as a DHCP server so I can SSH in when I'm not on my home network but I'm getting an error.

Below is my dhcpd.conf file:

    
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.1;
option routers 10.0.0.1;
option domain-name-servers 8.8.8.8;
option domain-name "mydomain.example";

subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.40 10.0.0.50; }

When I try to run it I get

root@PLT:~# sudo service isc-dhcp-server start
Launching both IPv4 and IPv6 servers (please configure INTERFACES in /etc/default/isc-dhcp-server if you only want one or the other).
 * Starting ISC DHCPv4 server dhcpd                                                                                      * check syslog for diagnostics.
                                                                                                                 [fail]

I used this guide from the ubuntu forms to help set it up. I suspect it's something wrong with my conf file. I'm also not sure how to check syslog for diagnostics.

  • 1
    Several standards and RFCs stand in your way: 10.0.0.45 is a non-routable IP address, and packets from that address won't get off the LAN; The DHCP protocol itself is non-routable. The DHCPDISCOVER message won't appear on the internet. – waltinator Apr 13 '22 at 23:20
  • @waltinator That is fine. I don't want the connect to leave LAN. I am referring to connecting the pi directly to the laptop with a cable so that there is a LAN between my laptop and the pi and I can configure the pi without connecting it to a monitor etc. – user783208 Apr 14 '22 at 00:55
  • If your goal is to connect the Raspberry Pi to the Windows computer, use Windows tools to create a WiFi hotspot. The WSL is an extra layer of visualization and hence complexity. Windows now has a native ssh client in the app store. – user68186 Apr 14 '22 at 02:07

1 Answers1

2

It could be coincidence, but I received an upvote in the last couple of hours on this answer regarding how to set up SSH on WSL to allow login from remote hosts. So I'm thinking you may have figured out the answer to that part of your question already. If not, check out that answer first for some background. However, if you really do need a DHCP server in WSL, then my suggestion for DHCP below will break that answer, at least to some degree.

Both SSH'ing into and setting up a DHCP server on WSL2 share the same core issue -- WSL2 operates in a virtual network that is NAT'd behind/inside the Windows host. It is not accessible on what you would normally consider the "local" network (the network the Windows host itself is on).

AFAIK, there's no way for DHCP to work with forwarding since it depends on broadcast traffic, but a new feature is coming to WSL that may running a DCHP server possible.

If you are on:

  • Windows 11
  • Pro/Education or higher versions
  • And are willing to run a Preview version of WSL

Then you can currently install the "Windows Subsystem for Linux Preview" from the Microsoft Store. Your current Ubuntu distribution will not need to be reinstalled.

This Preview version has a feature that allows you to select an alternative Hyper-V network switch, and set that switch to be Bridged. In theory, that would allow you to run a DHCP server in Ubuntu on WSL that would be accessible from the local network.

See this Reddit post and the associated blog post for details. In summary, you will:

  • Install the Preview version

  • Enable the Hyper-V feature in Windows

  • Update or create a .wslconfig in your Windows user profile directory with the following:

    [wsl2]
    networkingMode = bridged
    vmSwitch = Bridge
    

    The switch itself can be named whatever you want, but it needs to match the following ...

  • Create a new Hyper-V switch with the name used above.

  • Set it to Bridged

Ok, with that in mind, there is a known bug/limitation with the Preview version when it comes to WSL. You cannot SSH into Windows and access a WSL instance via the wsl command. My previous answer regarding SSH relies on this feature. For this reason, I don't personally use the Preview version.

However, with this in place, you should now be able to access the Ubuntu SSH server directly from the local network, so the ability to launch WSL from Windows OpenSSH isn't quite as critical.

Just be aware of the difference in behavior if you choose this route.

Another option

I haven't tested this either, but you may be able to run a DHCP server on Ubuntu running under WSL1, since it does operate in a "bridged" mode already.

In theory, it will work, but there's a slim change that some of the necessary functionality won't be implemented in WSL1.

NotTheDr01ds
  • 17,888