As we mentioned earlier, using Linux can become a good router. Today, this article will introduce how to use the route forwarding function to achieve shared Internet access. Interested friends can learn together.
First, the Linux system to open the IP forwarding function
Linux system to achieve the router function, you must first open the IP forwarding function in the Linux system kernel. We can check if it is enabled by the following command. Less /proc/sys/net/ipv4/ip_forward The content of this file is 0, which means that packet forwarding is prohibited. 1 means permission, and it is changed to 1. The IP forwarding routing function can be enabled using the command echo “1” ” /proc/sys/net/ipv4/ip_forward.
However, this method cannot be valid for a long time, and only guarantees that it is valid at the time. If the system operation is restarted, the command must be re-executed. Therefore, in order to ensure that the system routing function is permanently valid, use the vi editor to open the vi /etc/sysctl.conf configuration file, change net.ipv4.ip_forward = 0 to 1, and exit after saving. In this way, the kernel IP forwarding is not reset every time the system is rebooted.
two, Linux system to achieve the routing functionality, shared Internet access
implement routing functions under LINUX system, two methods to achieve, one is forwarding through NAT IPTABLES tool, One is implemented using a subset of the IP ROUTE command in the IPROUTER2 toolset. Each of these two methods has its own advantages and disadvantages. Which method is used depends mainly on which method your network uses to connect to the Internet.
The IPTABLES tool is suitable for dynamic IP addresses and fixed public IP addresses. It also provides a network address translation function. This function not only enables intranet PCs that use private IP addresses to connect to the Internet, but also provides The external network can access various network services in the intranet through the DNAT function to increase the security by hiding the content IP network segment. The IP ROUTE tool also adapts to the same two Internet access methods as IPTABELS, but does not provide NAT functionality.
However, there are many special network routing functions that can be achieved through the cooperation of these two tools, for example, policy routing, load balancing, and multi-WAN egress routing. Therefore, the author separately lists the command content of the tool to implement the routing function, and then introduces how to cooperate with these two tools to complete more advanced functions.
1. The NAT mode of the IPTABLES tool enables the LINUX routing function. The command to connect to the Internet through dynamic dialing is as follows:
# iptables -t nat -A POSTROUTING -d 192.168. 1.0/24 -s 0/0 -o ppp0 -j MASQUERD
where ppp0 is the name of your dial-up network interface. Before that, you need to set the content related to dialing. We can edit it by /The etc/sysconfig/network-scripts/ifcfg_ppp0 configuration file implements this functionality.
The connection method for connecting the Internet through the fixed public IP address is as follows:
# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 202.103 .224.58
Among them, this fixed public IP address is assigned to you by the local ISP. This is also assumed by the author. The specific IP address depends on the location of your ISP.
2, through the IP ROUTE tool to achieve the routing function of the Linux system
The command to connect to the Internet through the dynamic dial-up Internet access is as follows:
# ip route add Via ppp0 dev eth0
The command to connect to the Internet via fixed public IP is as follows:
# ip route add via 202.103.224.58 dev eth0
After the above two methods In any of the settings, our LINUX system has routing capabilities. In this way, PCs located inside the LAN can share the Internet through this LINUX router, but the precondition is to set the IP address of the PC in these LANs to any of the IP address segments, but not the same, 192.168. 1.2-192.168.1.254, at the same time, set their gateway address to all 192.168.1.1, which is the IP address of the LAN NIC connected to the LAN NIC.
Since the DHCP server is not used in the LAN we set up, all computers need to manually set the IP address during the process of accessing the Internet.
Summary
Using the routing function of Linux system to achieve shared Internet access, the implementation method is relatively simple, the most important thing is that this implementation method can not only reduce the occupation of IP resources, but also the hardware of Linux. The requirements are relatively low, unlike the windows system, which has high requirements for hardware.
The above is the use of Linux routing and forwarding to achieve shared Internet access methods, these are based on Linux can become a good router, if you want to achieve shared Internet access, try the method described in this article.
Lantern is a commonly used system monitoring tool, which is mostly used for Mac system and can also
Learning Linux is actually the process of learning Linux commands, just like learni
Linux system operation, many people are practical Golang development language, in o
openSUSE Linux is a kernel-based Linux operating system, has been upgraded to version 13.2, how many
HP notebook Debian compiler sound card driver method
Introduction to the Linux file system
Linux uses shell batch conversion file encoding method
Linux to view Oracle related process methods through ps command
Linux curl command operation example summary
Linux uses node.js to execute commands.
How does the CentOS system remove IP from the Fail2ban blacklist
Which is better for Linux compression tools gzip and pigz?
Linux system file permissions and access mode introduction
How to increase or decrease the file system space in Solaris
MSN cannot log in automatically in Longhorn?
The method of displaying the library in the Win10 folder navigation pane
How to set Win8.1 boot automatically login
Win10 prompt "can not find entry point dllregisterserver" solution
Windows2000 comprehensive optimization (3)
Using PPT2010 to make Apple-type labeling box
Market share finally surpassed Vista
Method of reinstalling system without optical drive floppy drive