This is called masquerade. I have used this, many years before, to share a dial-up to another pc connected with a crossover cable.
My laptop is connected wireless on internet.
I want to share my connection to the other pc.
I used a dedicated switch where i connect both my laptop and my pc. This has been tested.
Or can use a crossover cable to connect laptop and pc. I have not checked this.
On LAPTOP which is connected to internet with wireless
1. Create a file masq.sh and add the following exactly, in the end of file.
Code: Select all
#!/bin/sh
#
#Share my wireless connection to eth0
#Assuming wlan0 is your wireless WAN port, e.g. the laptop) and eth0 is your LAN port e.g your client PC
#and that you have connected your client PC to your host PC Laptop via a dedicated switch or (with a crossover ethernet cable)
ifconfig eth0 down
ifconfig eth0 192.168.10.1 netmask 255.255.255.0
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -F FORWARD
iptables -A FORWARD -j ACCEPT
iptables -nvL
2. install dnsmasq so your client pc should take an address using dhcp. So you can share your wireless connection to many pc's. In a common switch can use 7 pc's.
3. Edit the file /etc/dnsmasq.conf
and add these lines in the end.
Code: Select all
interface=eth0
dhcp-range=192.168.10.10,192.168.10.19,4h
4. start the dnsmasq
On every boot just type on laptop
on client pc type for testing. ( this not need on every boot of client pc. It will pick up an ip from dhcpcd)
Open a browser on client pc and you are on internet.
On my laptop typing the command sudo route i get
Code: Select all
djemos[~]$ sudo route
Password:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default dsldevice.lan 0.0.0.0 UG 0 0 0 wlan0
loopback * 255.0.0.0 U 0 0 0 lo
192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.10.0 * 255.255.255.0 U 0 0 0 eth0
On client pc
Code: Select all
djemos[~]$ sudo route
Password:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.10.1 0.0.0.0 UG 202 0 0 eth0
loopback * 255.0.0.0 U 0 0 0 lo
192.168.10.0 * 255.255.255.0 U 202 0 0 eth0
Code: Select all
djemos[~]$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.16 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::6ab5:99ff:fe66:a8c prefixlen 64 scopeid 0x20<link>
ether 68:b5:99:66:0a:8c txqueuelen 1000 (Ethernet)
RX packets 3063 bytes 2232352 (2.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2891 bytes 325686 (318.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 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Code: Select all
djemos[~]$ cat /etc/resolv.conf
# Generated by dhcpcd from eth0.dhcp
# /etc/resolv.conf.head can replace this line
nameserver 192.168.10.1
# /etc/resolv.conf.tail can replace this line
Of cource can use wicd on client pc. It will pick up an ip from wired net.