Remember the post about temporarily switching WIFI to access point mode? Of course not, it was a long time ago. Here it is:
habrahabr.ru/blogs/linux/122876 .
Today we will speak not about the access point, but about the mode of operation of the computer in which it acts as a router. This can be useful in the case when there is only one point of access to the Internet, and you need to connect several computers. Or, for example, the Internet is distributed over WIFI, there is one laptop with WIFI, and the second device has only an Ethernet interface.
We have
- Laptop with Ubuntu 11.10 and wireless network adapter
- Wireless Internet
- Computer with Ethernet interface
')
Task
- Get Internet access from your computer
Decision
Until recently, to solve the task, I copied the scripts from the topic about the access point and their rules. But the frequent need for such access has evolved a new small script.
The first script will install the necessary packages, namely dnsmasq, which acts as a dns / dhcp server.
install.sh#!/bin/bash # Install dns/dhcp server apt-get install dnsmasq # Stop installed service service dnsmasq stop # Disable autostart on boot update-rc.d dnsmasq disable
And the second script that puts the laptop into router mode and back.
start.sh #!/bin/bash INT=eth0 EXT=wlan0 INT_IP=192.168.2.2 INT_RANGE=192.168.2.10,192.168.2.50 # Start ifconfig $INT $INT_IP sysctl net.ipv4.ip_forward=1 iptables -t nat -A POSTROUTING -o $EXT -j MASQUERADE dnsmasq -d -zi $INT -F $INT_RANGE -C /dev/null -l /tmp/dnsmasq.leases # Stop iptables -D POSTROUTING -t nat -o $EXT -j MASQUERADE sysctl net.ipv4.ip_forward=0
Tested in Ubuntu 11.10, but can be used in any distribution, which is available to install dnsmasq.
Enjoy your experiments!
UPDATE :
Habravchane do not approve, moved to
Help Linux .