5

I want to connect two devices, the first is a laptop with ubuntu (connected to internet via wifi), and the second one is a device with a distro linux compiled with yocto. These two devices are connected each other with an ethernet cable. I want the internet acces on the second device. On the laptop i've setted a static IP on the eth interface (192.168.3.254), and i've allowed the wifi sharing option to other computers (so to the eth iface too). In the second device i've the following etc/network/interfaces:

auto eth0
iface eth0 inet static
    address 192.168.3.22
    netmask 255.255.255.0
    network 192.168.3.0
    gateway 192.168.3.254

Now i'm able to start ssh session, but the only ping that works on the secon device is on 192.168.3.254. I've tried to ping 8.8.8.8 or 1.1.1.1 but nothing! What i'm doing wrong?

3
  • You will have to give way more informations about "wifi sharing" on the laptop. The issue is probably on the laptop, not the yocto device.
    – A.B
    Mar 26, 2020 at 22:37
  • The laptop is connected to a WiFi Access Point with default settings. My only change to this settings (as mentioned in a lot of raspberry forum) is been enabling the ICS over all other computer connected.
    – Sguit
    Mar 26, 2020 at 22:50

3 Answers 3

7

There are two ways to accomplish this. I'm not sure how to go about this using a GUI, but here's the standard way on Ubuntu. I will use the UFW and netplan tools which come with later versions of Ubuntu, as an example. One of these options should be applied on the laptop.

Setup a NAT

The reason your current setup isn't working is that you haven't setup a NAT, or Network Address Translation. A NAT is what is responsible for changing the device's IP as packets enter and leave your NAT gateway. A wireless router does this, and this is the reason devices have private IP addresses, but can still contact the outside internet.

In Ubuntu, setting up a NAT is fairly straightforward because of the built-in UFW utility. In the file /etc/ufw/sysctl.conf, comment out the line net.ipv4.ip_forward=1.

Also, set this line in /etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"

Now, in the file /etc/ufw/before.rules, add these lines just before the filter rules:

*nat
:POSTROUTING ACCEPT [0:0]

-A POSTROUTING -o <WIRELESS INTERFACE> -j MASQUERADE

COMMIT

Change <WIRELESS INTERFACE> to the name of your wireless interface, found using ip link. Once you have made these changes, restart ufw to apply changes sudo systemctl restart ufw, and also make sure the firewall is enabled by running sudo ufw enable.

Your current configuration with static IPs on the ethernet interface will work fine, and your secondary device should now be able to contact the outside.

Setup a Bridge

Another option is to bridge your ethernet interface and your wireless interface, essentially turning your laptop into a network switch. This is the best option if you want your device to act as a normal device on your network (as in as far as the other devices in your network is concerned, this is just another wireless client). You can configure your interfaces in the file /etc/netplan/01-netcfg.yaml or /etc/netplan/50-cloud-init.yaml. Whichever file you have. This example assumed DHCP is provided from your wireless interface. If it is not, you can find other examples for netplan here.

network:
  version: 2
  renderer: networkd
  ethernets:
    <ETHERNET INTERFACE>:
      dhcp4: no
    <WIRELESS INTERFACE>:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - <ETHERNET INTERFACE>
        - <WIRELESS INTERFACE>

Change to the interface your secondary device is connected to.

Then, run sudo netplan apply to apply those changes. If you run ip a you can confirm that the bridge interface br0 exists. Now, once you connect the secondary device and enable DHCP on that device, it will obtain an IP address from the wireless router and act as any other wireless device does on the network.

The bridge is now your primary interface from your wireless router, meaning if you wanted to assign a static ip on your laptop, for example, you would need to assign it on the bridge interface, not the wireless interface.

1
  • Thanks! The NAT solution worked for me. Just make sure to setup DNS on the device manually.
    – orzechow
    Sep 11, 2023 at 9:04
6

Using GUI :

Connections > Wired Connection > IPv4 > Method: Shared to other comuputers

enter image description here

More info: https://askubuntu.com/questions/359856/share-wireless-internet-connection-through-ethernet

1
  • 1
    Wow. Why am I surprised that this "just works"?
    – cyqsimon
    Jun 12, 2023 at 7:55
0

Sharing Fedora wifi internet with Manjaro through ethernet. Gnome is on both sides. Everything can be done in the GUI. On server side (Fedora here) select "Shared to other computers", on client side "Automatic".

Even though it is automatic read the Details so you quickly understand what is going on. In particular the gateway or DNS is simply the server.

The netmask is not shown in GUI, it can be obtained with ifconfig.

In case of problem, check with ping then ssh (allow remote login in Sharing and manjaro password is manjaro).

Wit Mac OS sharing internet to Linux, the only thing to do is plug the cable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .