|
10 years ago 3 |
To share internet connection from your linux to windows/linux with squid3 proxy server and dhcp3 server
just follow the steps bellow:
1. First install squid3 and dhcp3-server
sudo apt-get install squid3
sudo apt-get install dhcp3-server (or install isc-dhcp-server from synaptic)
2.Suppose that the LAN connected network card is eth0 and the internet connected one is eth1
3.sudo gedit /etc/network/interfaces
Delete all the text and paste this text in your interfaces file:
#interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
post-up iptables-restore < /etc/iptables.up.rules
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
save the file and close
Here 192.168.1.1 is the IP Address of your LAN interface
4.Make a backup of your squid.conf for future reference
sudo cp /etc/squid3/squid.conf /etc/squid3/squid.conf.original
5.Configure squid3
sudo gedit /etc/squid3/squid.conf
Remove all the text and paste this text in your squid.conf file for a minimal configuration:
http_port 3128 transparent
acl LAN src 192.168.1.0/24
acl localnet src 127.0.0.1/255.255.255.255
http_access allow LAN
http_access allow localnet
cache_dir ufs /var/spool/squid3 20000 16 256
save the file and close
Where 192.168.1.0/24 is the range of your LAN interface.
5.sudo gedit /etc/sysctl.conf
Uncomment the lines:
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
uncommenting means removing the # from the beginning of the lines
6.sudo gedit /etc/iptables.up.rules
Paste this text in the file that opens up:
*nat
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.1.1:3128
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
-A POSTROUTING -s 192.168.1.0/24 -o eth1 -j MASQUERADE
COMMIT
Save and close this file.
7.sudo gedit /etc/rc.local
Paste this text at the end(before exit 0) of the file that opens up:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 –o eth1 -j MASQUERADE
8.sudo gedit /etc/default/dhcp3-server
Type eth0 in between the quotes in this line:
INTERFACES=""
Save and close the file
9.sudo gedit /etc/dhcp3/dhcpd.conf
Delete all the text and paste this text in the file that opens up:
authoritative;
default-lease-time 3600;
max-lease-time 3600;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.8.4;
option domain-name "my.domain.name";
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.2 192.168.1.253;
}
Save and close the file.
10.sudo /etc/init.d/squid3 restart
Now your other computers connected to the LAN with ip range 192.168.1.2 to 192.168.1.253 can connect to internet through proxy.
Change proxy settings on other computers (windows\linux) to your ip address i.e 192.168.1.1 & port 3128
On windows end:
in windows go to the control panel-internet options-connections(tab).click 'Lan settings'. check 'use a proxy server for your lan...' option. below it, put the host ip (192.168.1.1 in this case) and the port no. 3128. this is the system proxy for windows.
if you can set proxy seetings for google chrome then do it . it will do the same as above.
firefox may not detect the system proxy. in this case, options- advance- network (tab) -settings, then check maual proxy and put the ip and port. check 'use this proxy for all protocols'
This method is tested on linux mint 14.1 cinnamon and ubuntu 12.04 LTS
I think it will work on every linux mint and ubuntu version
You may want to skip the steps 8 and 9. This may not affect anything.
If you have another ip range, change the above ip informations carefully.
Be careful that the internet connected device used here is eth1. This may not happen all the time.
Change it according to your network devices
You don't have to start the squid3 proxy manually.It will start at every boot automatically.
You just have to connect your network devices correctly.
At first there may be a problem browsing through the LAN and you and other users may not see the computer lists in the LAN interfaces. Don't be afraid.it will be fixed in 24 hours.
your computer which has the internet connection may show the LAN interface unmanaged.It's not a problem at all. Whatever happens to the LAN , if connected properly, there will be no problem browsing the internet.
Good Luck.......
as per CdnLinuxUser's comment i added "On windows end:" section.