132

I want to share the wireless Internet connection on my desktop with my old laptop, through ethernet.

I have ticked the option "Make available to others" on both connections, on my desktop, but my laptop doesn't connect. Am I doing something wrong or is it a bug?

Eric Carvalho
  • 55,453

3 Answers3

138

On the server computer:

  1. On the computer, which is connected to the Internet, click the network icon in the panel and go to "Edit Connections..." at the bottom of the menu.

    Edit Connection...

  2. Double click your Wired Connection (Leave your wireless connection untouched, the one connected to Internet and the one you want to share, as I understand).

    Network Connections Dialog

  3. On the "IPv4 Settings tab", select Method: "Shared to other computers"

    Editing Wired Connection

  4. Reconnect by clicking on the Wired Network, so it gets a new IP address. (The two computers must be connected by an ethernet cable for this step, so connect them now if you haven't already.)

  5. Click on "Connection Information" in the network menu and write down the IP address and network mask (in my case it was assigned 10.42.0.1/255.255.255.0 but I do not know if that will always be the case).

    Connection Information

On the client computer:

  1. Go to "Edit Connections..." and assign a "Manual" Method. Assign an IP address on the same subnetwork (10.42.0.69 for example) and put the IP and network mask you wrote down in "Netmask" "Gateway" and "DNS servers"

    Editing Client Wired

  2. Reconnect to the network to let the new settings be assigned.

  3. Pat yourself on your back and surf away!!!

SuperMau
  • 1,683
0

With network-manager in KDE in 2022 I don't need to do anything too complicated: just create a new shared connection (default configuration works fine):

  1. open the configurations:

enter image description here

2.add a new connection

enter image description here

  1. select "Wired ethernet (shared)" (or similar), give it a name like partageinternet, and save (no need to configure it):

enter image description here

  1. Then, plug you ethernet cable to your other computer (tested with a rasperry). A new entry should appear in the Network Manager menu to start to share the previously created connection. Actually if the entry is not visible (in my case it did not appeared the first time, not sure why), you can force NM to start it:
$ nmcli connection show
…
partageinternet …
…
$ nmcli connection up partageinternet

That's all! The other computer should automatically connect.

tobiasBora
  • 2,588
0

How things look like on Ubuntu 23.10

This is how things look like now on a working setup between two Ubuntu 23.10 and topology:

Internet --- Wi-Fi --- Computer 1 --- Ethernet --- Computer 2

Computer 1

Open Settings -> Network.

Click the cog under Wired:

enter image description here

I don't think I changed anything here:

enter image description here

Select "Shared to other computers" (TODO how to do this from CLI? https://unix.stackexchange.com/questions/243408/share-wlan-connection-to-ethernet-using-command-line )

enter image description here

And then "Apply".

Next you also need:

sudo sysctl net.ipv4.ip_forward=1

If you set it to 0 which seems to be the default, then things don't work because "obviously" Computer 1 won't forward the packets from Computer 2 as we want, and the GUI procedure does not seem to affect it which is a shame. To make it permanent across reboots uncomment in /etc/sysctl.conf:

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

Computer 2

I don't think I changed anything in Computer 2, it's just set at "Automatic (DHCP)"

enter image description here

After this, Computer 2 can now connect to the Internet through Computer 1, e.g.:

ping example.com

Inspecting what the network looks like

In Computer 1:

ip a

shows:

2: enp1s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fc:5c:ee:24:fb:b4 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.1/24 brd 10.42.0.255 scope global noprefixroute enp1s0f0
       valid_lft forever preferred_lft forever
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 04:7b:cb:cc:1b:10 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.123/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp2s0
       valid_lft 81730sec preferred_lft 81730sec
    inet6 fe80::3597:15d8:74ff:e112/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

and Computer 2:

2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 54:e1:ad:b5:5b:08 brd ff:ff:ff:ff:ff:ff
    inet 10.42.0.70/24 brd 10.42.0.255 scope global dynamic noprefixroute enp0s31f6
       valid_lft 2914sec preferred_lft 2914sec
    inet6 fe80::a64f:794b:b8fa:5501/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

so we understand that these IPs were automatically negotiated with DHCP.

We can also see the IP assigned to Computer 2 from Computer 1 with:

sudo bash -c 'tail -n+1 /var/lib/NetworkManager/*.leases'

which outputs something like:

1707478545 54:e1:ad:b5:5b:08 10.42.0.70 ciro-p51 01:54:e1:ad:b5:5b:08

so we can also see the IP 10.42.0.70 is assigned to Computer 2. See also: How do I show active dhcp leases

For fun we can also now connect from one computer to the other with those IPs, e.g. from 1 to 2:

ping 10.42.0.70

and from 2 to 1:

ping 10.42.0.1

And for megafun, we can also run Wireshark on Computer 1 and watch as it receives and forward the ping packets from Computer 2. We watch on all interfaces with:

sudo wireshark -k -f 'icmp' -i enp1s0f0 -i wlp2s0

to capture both the Ethernet and Wi-Fi traffice. Then each ping request produces 4 lines on Wireshark:

         Time         Source           Dest             Hw src             Hw dst  Protocol
1 0.000000000     10.42.0.70  93.184.216.34  54:e1:ad:b5:5b:08  fc:5c:ee:24:fb:b4      ICMP  request  id=0x79ee, seq=8/2048, ttl=64 (reply in 4)
2 0.000074761  192.168.1.123  93.184.216.34  04:7b:cb:cc:1b:10  9c:53:22:17:e2:0e      ICMP  request  id=0x79ee, seq=8/2048, ttl=63 (reply in 3)
3 0.098882299  93.184.216.34  192.168.1.123  9c:53:22:17:e2:0e  04:7b:cb:cc:1b:10      ICMP  reply    id=0x79ee, seq=8/2048, ttl=51 (request in 2)
4 0.098952451  93.184.216.34     10.42.0.70  fc:5c:ee:24:fb:b4  54:e1:ad:b5:5b:08      ICMP  reply    id=0x79ee, seq=8/2048, ttl=50 (request in 1)

so we can beautifully watch as Computer 1 receives Ethernet frames from Ethernet, opens them up, wraps them into new frames for Wi-Fi, and then does the same in reverse when the reply comes from example.com.

Tested with computer 1 = Lenovo ThinkPad P14s, Computer 2 = Lenovo ThinkPad P51 with Wi-Fi turned off.

Related