Article Title: Network Management Experience: creating an Internet cafe Linux proxy server. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In many universities and research institutions, there are not many legal ip addresses and ports. Therefore, many departments use proxy to access the Internet. It is convenient to use Microsoft's ProxyServer, but it is inefficient and has poor performance, and the most important thing is that the cost is too high.
Therefore, using a cheap Linux server as a proxy to access the Internet has become a good solution. After several days of debugging, I used Linux as a transparent gateway server, so that other machines in the dormitory can share a network through a Linux machine. I feel very good. The implementation method is to set IP camouflage.
Background
Machine 0:
OS: Redhat 6.0, dual Nic installed successfully
Eth0: 192.168.2.61, connected to the Campus Network
Eth0's NetMask: 255.255.254.0
Eth1: 192.168.11.1, connected to the dormitory LAN
Eth1's NetMask 255.255.255.0
The IP address of the dormitory LAN is a custom IP address, which is an invalid IP address.
Machine 1:
OS: Win9x
IP: 192.168.11.2
GateWay: 192.168.11.1/* eth1 of machine 0 */
NetMak: 255.255.255.0
DNS: 202.116.64.3/* name server of the Campus Network */
Purpose
So that machine 1 can be connected to the campus network through machine 0, just as machine 1 is directly connected to the campus network. Therefore, machine 0 is called a transparent gateway.
Principle
Because only the IP address of machine 0 is a valid address, machine 1 needs to pass the packet sent by machine 1 to the campus network.
The machine 0 disguised and then forwarded. During this period, machine 0 extracts and stores the local IP address from the IP packet of machine 1, replace the local address of machine 0 and then forward the returned data packets to machine 1 after machine 0 is restored.
Procedure
1. Ensure that machine 0 can go out of the campus network, Ping machine 1, and Ping machine 0. As
In this case, we will not discuss this issue.
2. Open xwindows on machine 0, run: netcfg select routing, allow (enable) Network
Packet Forwarding (IPV4 ). Create a file on machine 0: rules chmod + x rules to make rules
To an executable file.
= (Echo 1>/proc/sys/net/ipv4/ip_forward)
3. Create a rules file. The specific path can be put in/sbin. Edit this file and enter the following content:
# Deny all ip forwarding by default .. 0
/Sbin/ipchains-P forward DENY
# Allow the dormitory network to use ip forwarding through machine 0. For ipchains, see man ipchains or ipchains.
How to (refer to building an ipchains-based Linux firewall on our site)
/Sbin/ipchains-A forward-j ACCEPT-I eth1-s 192.168.0.0/24
/Sbin/ipchains-A forward-j MASQ-I eth0-s 192.168.0.0/24
# Add the camouflage module you need.
/Sbin/modprobe ip_masq_ftp
/Sbin/modprobe ip_masq_quake
/Sbin/modprobe ip_masq_irc
/Sbin/modprobe ip_masq_user
/Sbin/modprobe ip_masq_raudio
4. Run/sbin/rules.
If you add the Run rules command to/etc/rc. d/rc. local, ipchains can be automatically executed at startup. This method is also applicable to dial-up Internet access.
Simple Method:
In fact, using LINUX as a gateway (only as a gateway that can drive the entire local area of the INTERNET) is very simple, as long as the first connection
Run the following two commands on the INTERNET,
(Of course, the root identity must be used ):
Command 1:
# Echo 1>/proc/sys/net/ipv4/ip_forward
Note: Network Packet Forwarding (IPV4) is allowed)
Command 2:
#/Sbin/ipchains-A forward-j MASQ-S xxx. xxx/32
Note: xxx. xxx. xxx. xxx is the IP address of a machine in the LAN. This command allows xxx. xxx. xxx. the IP packet request of the xxx machine can be disguised to execute these two commands.
Finally: Is there a security problem? Enter the Intranet address of the Linux host for All Intranet machine gateways.