From charlesreid1

Up: Ubuntu/Bespin

Next: Ubuntu/Bespin/Gnome Setup

Aptitude update

During installation, we allow setup to join the wifi network. On first boot, the network manager will be running and will be connected to the same wifi network. We will disable network manager eventually, but first get some software.

sudo apt-get update
sudo apt-get -y install vim gnome-tweak-tool net-tools

Set caps lock as a control key.

Allow sudo for user

Create wheel group:

sudo groupadd wheel

Add user to group:

sudo usermod -a -G wheel <your-username-here>

Allow wheel group users passwordless sudo, first use visudo to edit the sudoers file:

EDITOR=vi visudo

Now add this line to the end:

%wheel ALL=(ALL) NOPASSWD: ALL

Install ssh

Install ssh and server:

sudo apt-get install ssh

Start the server:

sudo service ssh start

Install trusted ssh key

If you want, set up a machine to securely SSH into the Ubuntu server.

From the machine you want to SSH FROM:

cat ~/.ssh/id_rsa.pub

Copy this text. Now in another terminal, ssh into the Ubuntu server. Paste the output of the above command into the file:

~/.ssh/authorized_keys

Now verify that SSHing into the Ubuntu server will not ask you for a password.

Configure WPA Supplicant

We want to configure wifi manually, and disable the network manager. This requires some preparation to manually join a wifi network with wpa supplicant.

First set your wpa supplicant to join a wifi network.

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="yournetworkhere"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="yourpskhere"
}

Don't forget the WPA supplicant service (two steps down)

Name Network Interfaces

Ubuntu 18.04 does this annoying thing where the wifi interfaces are awful to type and impossible to remember because they contain the ENTIRE MAC ADDRESS OF THE DEVICE.

To fix this, rename the network devices. The following file will not exist on a fresh Ubuntu install, so create it with the following contents (one line per network device you want to rename):

/etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="02:01:02:03:04:05", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="wlan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="02:01:02:03:04:06", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="wlan1"

Configure Network Interfaces

Next add the wifi interface to the network interfaces file:

  • wlan0 will be joining an existing wifi network

The following lines should be APPENDED to any existing network interfaces file:

/etc/network/interfaces

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

WPA Supplicant Startup Service

Copy a wpa supplicant service template:

sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service

Edit the file

sudo vim /etc/systemd/system/wpa_supplicant.service

Change this line from this:

ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant

to this:

ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0

Also, remove the following line if it is present:

Alias=dbus-fi.w1.wpa_supplicant1.service # DELETE ME!

Now enable this service to start on boot:

sudo systemctl enable wpa_supplicant.service

Dhclient on Startup

The dhclient command must be run on startup after the wifi is set up so that bespin will get an IP address.

Create an rc.local startup service:

/etc/systemd/system/rc-local.service

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Now add the dhclient command to rc.local:

/etc/rc.local

#!/bin/bash
/sbin/dhclient wlan0
exit 0

Make it executable:

chmod 744 /etc/rc.local

Now enable the rc-local service:

sudo systemctl enable rc-local.service

Verify it works okay:

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

Requesting Static IP

If you want to request a static IP from the router, add this to the dhclient config file:

/etc/dhcp/dhclient.conf

interface "wlan0" {
     send dhcp-requested-address 192.168.0.122;
}

Disable Network Manager

Next step is to disable the network manager. It takes a lot of commands. Too many commands.

sudo systemctl stop NetworkManager.service
sudo systemctl disable NetworkManager.service

and three more services:

sudo systemctl stop NetworkManager-wait-online.service
sudo systemctl disable NetworkManager-wait-online.service

sudo systemctl stop NetworkManager-dispatcher.service
sudo systemctl disable NetworkManager-dispatcher.service

sudo systemctl stop network-manager.service
sudo systemctl disable network-manager.service

Don't uninstall it, though, because that will uninstall a bunch of other important gnome packages and you'll be left with a stupid broken ubuntu.

Now reboot

sudo reboot now

Run sudo service --status-all and verify network manager is not running.

Test Wifi

Test that everything is working as expected by running the ifconfig and iwconfig commands.

  • ifconfig should show an IP address for the wlan0 interface that the wpa_supplicant connects with
  • iwconfig should show the name of the wifi network that wlan0 is connected to (same one defined in wpa_supplicant.conf)

Troubleshooting

If you don't have an IPv4 address, troubleshoot with the following commands:

Check if you can reach the internet:

ping google.com

Check logs from dhcp service started by rc.local (this gets an IP address from the router and is the most likely culprit):

sudo service rc-local status

Check logs from wpa supplicant:

sudo service wpa_supplicant status