0

I cannot login to a 16.04.4 LTS desktop installation after reboot via SSH unless I first login to the console locally (set to boot text only, not GUI).

According to this answer, network connections must be "system connections" in order for them to resolve (acquire an IP from DHCP) at boot time, prior to login. In this Ubuntu help tutorial, nothing is mentioned about initializing a connection prior to login, and this answer suggests simply modifying /etc/network/interfaces. I've tried this last answer, but I still can't ping the host until a local login is completed and the network connection is initialized.

Yes, I'm aware that my connections may not be named eth0. I've set them up as follows ...

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet dhcp

#_#auto enp0s25
#_#iface enp0s25 inet dhcp
#_#
#_#auto wlp2s0
#_#iface wlp2s0 inet dhcp

... where all of the #_# commented lines were uncommented, but that actually caused another issue, because then ubuntu made another set of similarly named interfaces and no networking worked at all...

How do I set the interfaces to properly initialize at boot instead of at login?

user3.1415927
  • 178
  • 1
  • 14
  • 1
    If the connection had to be a "system connection" then Ubuntu server would not work. The network is supposed to start up before you even get to a login screen. I run 16.04 at home and I only have the auto lo and iface lo inet loopback lines in my /etc/network/interfaces file. – Terrance Jul 25 '18 at 18:34
  • @Terrance Can you SSH in without logging in after a cold boot? – user3.1415927 Jul 25 '18 at 18:42
  • Yes, I sure can. I have turned off my autologin that was setup and I cold booted my system and it works fine. – Terrance Jul 25 '18 at 18:48
  • What @Terrance says. Moreover: 1) after a power outage, the server only needs to be powered on for it to access the network; 2) unattended-upgrades occasionally needs the server to reboot, e.g. at 03:00 AM. Would be a nuisance to get up and log in locally before it got access to the network. – Jos Jul 25 '18 at 18:54
  • Okay, so what troubleshooting steps should I take?... – user3.1415927 Jul 25 '18 at 18:56
  • For the record, this is a wireless network connection I’m trying to reestablish. – user3.1415927 Jul 25 '18 at 18:57
  • Using Wifi does make a difference. You should have mentioned that in your question. See the answers here for configuring before the login: https://askubuntu.com/questions/16376/connect-to-network-before-user-login – Terrance Jul 25 '18 at 19:11
  • @Terrance That did it. Make it an answer and I'll accept. Also, I'll add it as a comment to your answer: the psk value is in plaintext. The information from this tutorial I linked in my question gave me the information I needed to encrypt the WPA passphrase. – user3.1415927 Jul 27 '18 at 19:06
  • Also, @Terrance, I apologize - I missed the wifi bit at the time of my initial question. – user3.1415927 Jul 27 '18 at 19:07

1 Answers1

0

First, your wireless will never connect unless you specify the SSID (router) you want to connect to, as well as supply the WPA2 password. Also, it will often be difficult to ssh to your computer that gets a dynamic, probably changing, IP address. Let’s create a proper interfaces file.

First, find the relevant interface name, if not wlp2s0, with the terminal command:

iwconfig

Second, I suggest a static, never changing, IP address. Pick one outside the range used by the DHCP server in the router. Here is an example: http://www.abyssunderground.co.uk/images/router/dhcp.gif

In this example, the DHCP range is from x.100 to x.159. Therefore, static IP addresses in the range of x.2 to x.99 or x.160 to x.253 are safe.

Ideally, you can check the DHCP range in the administrative pages of the router. If you are unable to do so, check the IP addresses of other connected devices in the network; phones, iPads, etc. You may see them all in a close range, say x.2 to x.10. Then you may probably be safe setting a static IP address far away, say x.200.

Now let’s set up /etc/network/interfaces. I suggest:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#auto enp0s25
#iface enp0s25 inet dhcp

auto wlp2s0
iface wlp2s0 inet static
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1 8.8.8.8
wpa-ssid <your_network_name>
wpa-psk <your_secret_password>

Of course, substitute your exact details here. Restart the interface:

sudo ifdown wlp2s0 && sudo ifup -v wlp2s0

The -v for verbose should produce output that tells if there is a successful connection.

Test:

ping -c3 192.168.1.1
ping -c3 www.ubuntu.com

If you get ping returns, you are connected.

Reboot. Can you ssh into 192.168.1.200?

chili555
  • 60,188
  • You'll note I actually already tried editing the file you suggest. In addition, I tried using the simplest setup (DHCP), which would work in my case, since I have static IPs configured on the routing level. It didn't work even before you wrote this answer. – user3.1415927 Jul 27 '18 at 19:04
  • Your file above in your question lacks the needed SSID and password. Isn't that why it didn't work? – chili555 Jul 27 '18 at 19:50
  • No, I had not known about the NetworkManager file, but I had tried entering the network info (SSID, etc) elsewhere. (Unsuccessfully..) – user3.1415927 Jul 27 '18 at 19:56
  • When /etc/network/interfaces is populated, it supersedes NM by default. If it is wrong there, it won't work, no matter if the needed SSID and password are entered in NM. If interfaces is wrong, it won't connect. – chili555 Jul 27 '18 at 20:11