If you have two laptops but only one IP address that can access the Internet, what should you do if you want to achieve simultaneous Internet access between the two computers without purchasing a router?
My suggestion is that if you are using a linux operating system, let's start the iptables journey together. The network features are rich enough to be unexpected. Happy!
Okay, no worries. Start chatting seriously.
To share one ip address with two or more computers, we will think of NAT network address translation technology. If you are interested, you can find a search engine. Another point is that if the host acting as a router has two NICs, data forwarding between the two NICs should be allowed.
Follow these steps to enable multiple hosts to access the Internet using one available IP address through NAT.
1. Set ip Forwarding permission
In the/proc/sys/net/ipv4 directory, set the content of the file ip_forward to 1 after enabling the file using vi, or directly use echo 1> ip_forward)
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/0351134196-0.jpg "/>
2. Activate iptables
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/0351134A4-1.jpg "/>
3. Activate the NAT Function in iptables and set nat for those packets. In this article, we perform nat for packets from 10.1.1.0/24. -O indicates the exit,-s indicates the source address,-j indicates the action to be taken, and MASQUERADE indicates NAT.
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/035113M25-2.jpg "/>
4. View nat-related iptables. Pay attention to the POSTROUTING items.
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/0351135W5-3.jpg "/>
5. The reason why the filter tables rule is cleared is that the FILTER table does not cause any obstacle to the experiment, so you can set the table later)
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "src =" http://www.bkjia.com/uploads/allimg/131227/0351135024-4.jpg "alt =" "/>
6. Set the wlan0 address
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/03511342N-5.jpg "/>
7. Set wireless parameters such as SSID
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131227/0351131224-6.jpg "/>
8. Set the infinite parameter SSID on other hosts to be the same as that set on the above host, so you can set the network security. The IP address of the host is set to 10.1.1.0/24, and the gateway is set to 10.1.1.254 of the wlan0 address of the host above. You can also set a DNS address that can be used by yourself. If the DHCP server is enabled and configured on the host, other hosts can access the Internet.
Now, other hosts can access the Internet ~ Enjoy it!
This article from the "struggle to achieve excellence" blog, please be sure to keep this source http://tiger506.blog.51cto.com/318536/400185