I want to share internet from my Ubuntu 18.04 PC to another 3 pcs in a network via a hub through ethernet. Please help me.
1 Answers
If I understand well, you want your Ubuntu 18.04 PC to act like a router for the remaining 3 PCs.
To do it right, you ought to have two ethernet RJ-45 sockets on your Ubuntu box and a small network switch.
Your best option is to configure NAT via iptables and give DHCP addresses to 3 PCs.
See https://www.howtoforge.com/nat_iptables and https://linuxconfig.org/what-is-dhcp-and-how-to-configure-dhcp-server-in-linux
Alternatively, you can use static addresses for 3 PCs, but they have to be on a separate network for routing to work ...
NAT can be provided with this simple GPL'ed script
http://domac.alu.hr/~mtodorov/adm/iptables-nat
You need to configure the second interface in Ubuntu PC for your second LAN card. Typically these will be eth0 as default which connects to ISP's router-modem and eth1 which connects to your 3 PCs via your 8 port hub. eth0 will have the address assigned from your ISP's router-modem and it will typically look like 192.168.1.2/24 or something like that. You need to know how to configure eth1 interface for the internal network with 8 port hub and 3 PCs. This belongs to /etc/network/interfaces . (Or is it netplan in Ubuntu 18.04.02 LTS?) You will want your 3 PCs on a different network, say 192.168.2.0/24 . Netmask will be 255.255.255.0 , for both networks. Assign addresses like 192.168.2.2, 192.168.2.3 and 192.168.2.4 to your PCs. This choice simplifies as you don't have to configure DHCP. Then NAT and IP forwarding on Ubuntu PC will do the magic. The script which I have provided works well in an environment with two networks. I don't know your level of knowledge, so I tried to simplify it as good as it is possible.
3 PCs connected to 8 port hub must have Ubuntu PC configured as their default gateway.
Ubuntu PC will receive DHCP (dynamic) address from ISP, and will offer static addresses to 3 PCs on the hub. But, alternatively, you can configure dhcpd on Ubuntu to give dynamic addresses to 3 PCs, too.
netplan configuring of networks is somewhat new to me. I used to setup /etc/network/interfaces which is somewhat simpler.
The problem is that Ubuntu 18.04 LTS, unlike previous versions like 16.04 LTS, uses /etc/netplan/*.yaml configuration instead of /etc/network/interfaces ...
You can try to understand netplan configuration by looking at these examples. Good luck there!
- 361
