Access Point: Keep Ubuntu 22.04 LTS Laptop Connected to the Internet via Ethernet
In this article, we will discuss how to set up an access point on your Ubuntu 22.04 LTS laptop to connect an Ethernet-only device to the internet. This setup is useful when you have a small computing environment and need to share your laptop's internet connection with other devices.
Prerequisites
Before we begin, make sure you have the following:
- A laptop running Ubuntu 22.04 LTS
- An Ethernet-only device that you want to connect to the internet
- An active internet connection on your laptop
Setting Up the Access Point
To set up the access point, follow these steps:
- Open the Terminal application on your Ubuntu laptop.
- Install the necessary packages by running the following command:
sudo apt-get install hostapd dnsmasq
This command installs the Host Access Point Daemon (hostapd) and the DNS Masquerade Agent (dnsmasq) packages.
- Create a new configuration file for hostapd by running the following command:
sudo nano /etc/hostapd/hostapd.conf
This command opens the nano text editor. Add the following configuration to the file:
interface=wlan0
driver=nl80211
ssid=MyAccessPoint
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MySecretPassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
This configuration sets up a wireless access point with the SSID "MyAccessPoint" and the password "MySecretPassphrase". You can change these values to suit your needs.
- Save and close the file by pressing Ctrl+X, then Y, then Enter.
- Create a new configuration file for dnsmasq by running the following command:
sudo nano /etc/dnsmasq.conf
This command opens the nano text editor. Add the following configuration to the file:
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.10,24h
This configuration sets up a DHCP server on the wireless interface and assigns IP addresses in the 10.0.0.0/24 range to connected devices.
- Save and close the file by pressing Ctrl+X, then Y, then Enter.
- Edit the /etc/default/hostapd file to disable the systemd service:
sudo nano /etc/default/hostapd
Change the following line:
#DAEMON_CONF=""
to
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Save and close the file by pressing Ctrl+X, then Y, then Enter.
- Enable IP forwarding by running the following command:
sudo sysctl -w net.ipv4.ip_forward=1
This command enables IP forwarding, which allows your laptop to share its internet connection with other devices.
- Set up NAT (Network Address Translation) by running the following command:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
This command sets up NAT for the eth0 interface, which allows connected devices to access the internet through your laptop's internet connection.
- Start the hostapd and dnsmasq services by running the following commands:
sudo systemctl start hostapd
sudo systemctl start dnsmasq
This command starts the hostapd and dnsmasq services, which sets up the wireless access point and the DHCP server.
Connecting the Ethernet-only Device
To connect the Ethernet-only device to the access point, follow these steps:
- Connect the Ethernet cable from the device to your Ubuntu laptop.
- Configure the device's network settings to use the following values:
- IP address: 10.0.0.2
- Subnet mask: 255.255.255.0
- Default gateway: 10.0.0.1
- DNS server: 10.0.0.1
These values match the DHCP server configuration on your Ubuntu laptop.
- In this article, we discussed how to set up an access point on your Ubuntu 22.04 LTS laptop to connect an Ethernet-only device to the internet.
- We installed the necessary packages, created configuration files for hostapd and dnsmasq, and enabled IP forwarding and NAT on our Ubuntu laptop.
- We connected the Ethernet-only device to our Ubuntu laptop and configured its network settings to use the access point.