Standard Operating Procedure (SOP) for implementing network sharing via command line (CLI) on Ubuntu.
Connection Method:
Raspberry Pi <---> Hub(USB to Ethernet) <---> Ethernet Cable <---> Ubuntu PC Ethernet Port (enp45s0)
Goal: Ubuntu PC connects to internet via Wi-Fi and shares network to Ethernet port, allowing Raspberry Pi to get IP (10.42.0.x) and access internet.
First check the network card name and corresponding connection name (NAME).
nmcli deviceGoal: Find the row where TYPE is ethernet.
Assumed result: DEVICE is enp45s0, CONNECTION is Wired connection 1.
Change the IPv4 method of the wired connection to shared (equivalent to "Allow other users to connect through this computer" in Windows).
nmcli connection modify "Wired connection 1" ipv4.method sharedAfter configuration changes, you must restart the interface to start the DHCP service.
nmcli connection down "Wired connection 1"
nmcli connection up "Wired connection 1"Confirm that the Ubuntu Ethernet port has become the gateway IP (usually 10.42.0.1).
ifconfig enp45s0
# or
ip addr show enp45s0Scan the 10.42.0.x subnet to find devices other than .1.
sudo nmap -sn 10.42.0.0/24If nmap is not installed, you can use these alternatives:
# Method 1: Use arp
arp -n
# Method 2: View DHCP leases
cat /var/lib/misc/dnsmasq.leasesOnce you have the IP (e.g., 10.42.0.75), log in directly.
ssh pollen@10.42.0.75This configuration is permanent. Next time you unplug the Raspberry Pi and plug it back in days later, as long as it's plugged into the same Ethernet port, Ubuntu will automatically recognize and start shared mode again without needing to re-enter commands.
If you later want to plug this Ethernet port into a wall router for internet, remember to change the mode back to "auto":
nmcli connection modify "Wired connection 1" ipv4.method auto
nmcli connection up "Wired connection 1"Raspberry Pi network status example:
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.42.0.75 netmask 255.255.255.0 broadcast 10.42.0.255
ether 6c:1f:f7:24:1f:fd txqueuelen 1000 (Ethernet)
WiFi connection status:
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.57.101.85 netmask 255.255.255.0 broadcast 10.57.101.255
ether 2c:cf:67:f8:b7:44 txqueuelen 1000 (Ethernet)
Ensure WiFi is configured for auto-connection:
# Check auto-connection settings
nmcli connection show "YOUR_WIFI_SSID" | grep autoconnect
# Output should be:
# connection.autoconnect: yes# Connect to WiFi
sudo nmcli device wifi connect "SSID_NAME" password "PASSWORD"
# View all connections
nmcli connection showA: Confirm the following:
- Ethernet cable is plugged in properly
- Ubuntu shared mode is enabled
- Raspberry Pi is powered on
- Use
arp -nor check DHCP leases
A: Check:
- IP address is correct
- Raspberry Pi SSH service is running
- Firewall is not blocking connection
A: Check:
- Ubuntu PC is connected to internet
- Ubuntu firewall/NAT settings
- DNS resolution is working