How to share the internet connection from Linux to clients?
by Jason.nix from LinuxQuestions.org on (#6D03V)
Hello,
I want to share my Linux internet with other clients like Windows OS in a local network. My Linux box has two NICs as below:
Code:enp0s3: Internet (10.0.2.15 )
enp0s8: Local NIC (192.168.1.20)These NICs configurations are:
Code:# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:feed:b47c prefixlen 64 scopeid 0x20<link>
ether 08:00:27:ed:b4:7c txqueuelen 1000 (Ethernet)
RX packets 35870 bytes 41340847 (39.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16911 bytes 2970100 (2.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.20 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe74:6397 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:74:63:97 txqueuelen 1000 (Ethernet)
RX packets 124 bytes 12649 (12.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 2100 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 6558 bytes 26412423 (25.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6558 bytes 26412423 (25.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0And:
Code:# cat /etc/network/interfaces.d/ifcfg-enp0s8
auto enp0s8
iface enp0s8 inet static
address 192.168.1.20
netmask 255.255.255.0On Linux box, I have internet:
Code:# ping google.com
PING google.com (216.239.38.120) 56(84) bytes of data.
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=1 ttl=63 time=28.7 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=2 ttl=63 time=29.4 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=3 ttl=63 time=28.4 msBoth machines (Linux and Windows) can ping each other:
Code:# ping 192.168.1.21
PING 192.168.1.21 (192.168.1.21) 56(84) bytes of data.
64 bytes from 192.168.1.21: icmp_seq=1 ttl=128 time=1.04 ms
64 bytes from 192.168.1.21: icmp_seq=2 ttl=128 time=1.06 ms
64 bytes from 192.168.1.21: icmp_seq=3 ttl=128 time=1.03 ms
64 bytes from 192.168.1.21: icmp_seq=4 ttl=128 time=1.05 msAnd:
Code:C:\Windows\system32>ping 192.168.1.20
Pinging 192.168.1.20 with 32 bytes of data:
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.1.20:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\Windows\system32>I activated IP forwarding:
Code:# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1Then, I did the following iptables commands to share the Internet connection:
Code:$ sudo iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -t nat -I POSTROUTING -o enp0s3 -j MASQUERADEMy Windows OS NIC configuration is as below:
Attachment 41330
But, on Windows OS, I have not internet. Why?
Code:C:\Windows\system32>ping google.com
Ping request could not find host google.com. Please check the name and try again.
C:\Windows\system32>Thank you.
Attached Thumbnails
I want to share my Linux internet with other clients like Windows OS in a local network. My Linux box has two NICs as below:
Code:enp0s3: Internet (10.0.2.15 )
enp0s8: Local NIC (192.168.1.20)These NICs configurations are:
Code:# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:feed:b47c prefixlen 64 scopeid 0x20<link>
ether 08:00:27:ed:b4:7c txqueuelen 1000 (Ethernet)
RX packets 35870 bytes 41340847 (39.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16911 bytes 2970100 (2.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.20 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe74:6397 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:74:63:97 txqueuelen 1000 (Ethernet)
RX packets 124 bytes 12649 (12.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 2100 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 6558 bytes 26412423 (25.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6558 bytes 26412423 (25.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0And:
Code:# cat /etc/network/interfaces.d/ifcfg-enp0s8
auto enp0s8
iface enp0s8 inet static
address 192.168.1.20
netmask 255.255.255.0On Linux box, I have internet:
Code:# ping google.com
PING google.com (216.239.38.120) 56(84) bytes of data.
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=1 ttl=63 time=28.7 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=2 ttl=63 time=29.4 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=3 ttl=63 time=28.4 msBoth machines (Linux and Windows) can ping each other:
Code:# ping 192.168.1.21
PING 192.168.1.21 (192.168.1.21) 56(84) bytes of data.
64 bytes from 192.168.1.21: icmp_seq=1 ttl=128 time=1.04 ms
64 bytes from 192.168.1.21: icmp_seq=2 ttl=128 time=1.06 ms
64 bytes from 192.168.1.21: icmp_seq=3 ttl=128 time=1.03 ms
64 bytes from 192.168.1.21: icmp_seq=4 ttl=128 time=1.05 msAnd:
Code:C:\Windows\system32>ping 192.168.1.20
Pinging 192.168.1.20 with 32 bytes of data:
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Reply from 192.168.1.20: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.1.20:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\Windows\system32>I activated IP forwarding:
Code:# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1Then, I did the following iptables commands to share the Internet connection:
Code:$ sudo iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -t nat -I POSTROUTING -o enp0s3 -j MASQUERADEMy Windows OS NIC configuration is as below:
Attachment 41330
But, on Windows OS, I have not internet. Why?
Code:C:\Windows\system32>ping google.com
Ping request could not find host google.com. Please check the name and try again.
C:\Windows\system32>Thank you.
Attached Thumbnails