[Tutorial] How to share wireless internet to an Ethernet connection

Wireless Internet to Ethernet

Hey everyone! Here’s a quick tutorial on how to share a wireless internet connection over an Ethernet connection, enabling other devices to access the internet via the Ethernet network created on Mecha Comet.

Preview


Prerequisites

  • Ensure you have nmcli and nftables installed on Mecha Comet.
  • You need sudo privileges to execute the commands.
  • Replace wlan0 and end0 with your actual Wireless interface and outbound network interface names.
  • Ensure Mecha Comet is connected to wireless and have internet access.

Steps to Set Up Ethernet Sharing

1. Connect Mecha Comet to a Device with an Ethernet Port

Physically connect the Mecha Comet to another device (e.g., a laptop / desktop / mecha comet) using an Ethernet cable. Ensure the Ethernet port is functional on both devices.


2. Check Existing Network Connections

Run the following command to list the available network connections:

nmcli connection show

Identify the name of the Ethernet connection you want to modify (e.g., Wired connection 1).


3. Configure IPv4 Method to Shared

Modify the Ethernet connection to use a shared IPv4 method:

sudo nmcli connection modify "<connection-name>" ipv4.method shared

Example:

sudo nmcli connection modify "Wired connection 1" ipv4.method shared

4. Bring Up the Ethernet Connection

Activate the Ethernet connection:

sudo nmcli connection up "<connection-name>"

Example:

sudo nmcli connection up "Wired connection 1"

5. Configure NAT with nftables

5.1 Create a NAT Table

Add a new NAT table:

sudo nft add table ip nat

5.2 Add a NAT Chain

Create a chain for postrouting in the NAT table:

sudo nft add chain ip nat POSTROUTING { type nat hook postrouting priority 100 \; }

5.3 Add a Masquerade Rule

Add a masquerade rule for outgoing traffic through the Wireless interface:

sudo nft add rule ip nat POSTROUTING oif "wlan0" masquerade
  • Replace wlan0 with your Wireless interface name.

Verification

Check the Ethernet Connection Status

Use the following command to verify the Ethernet connection status:

nmcli device status

Verify nftables Rules

Check the NAT table rules to confirm the configuration:

sudo nft list table ip nat

Test Internet Connectivity on the Connected Device

Ensure the device connected via Ethernet can access the internet. Open a browser or run a ping command to verify connectivity.


Notes

  • Ensure your Ethernet adapter is functional and properly connected.
  • Replace interface names as needed for your specific setup.

Troubleshooting

  • If the Ethernet connection fails to start, ensure the cable is securely connected.
  • Verify that nftables is enabled and properly configured.

By following these steps, the connected device should now have internet access via the Ethernet connection.

1 Like