How to configure IPMasq firewall in Linux

Source: Internet
Author: User
Article Title: how to configure IPMasq firewall in Linux. 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.
◎ Li weige Hao Lirong
  
  
This article describes how to use the IP Masquerade (IP Masq) Firewall function in Linux. IP Masq can be used to implement NAT. This is one of the main functions of the network firewall. It is used for shared Internet access services for small and medium-sized enterprises, public institutions, and residential communities through a single registered IP address, in particular, with the popularization of broadband networks, a large number of users need to use the Internet. To solve the IP address shortage problem, using IP Masq in Linux is an ideal solution. To implement IP Masq in Linux, you need to solve two problems: correct installation of network dual-nic and correct setting of IP Masq.
  
1. Install dual NICs in Linux
  
1. device Environment
① IBM is compatible with one PC and one IDE hard disk.
② Turbo Linux Operating System 6.0.
③ 3Com ISA Ethernet Card 3C509B-TPO.
2. Installation Process
① In the DOS system, use 3c509bnetwork card driver to debug the program configuration with 3c5x9cmd.exe and test the parameters of two 3Com ISA NICs (mainly IRQ interrupt number and I/O memory address) to ensure the normal operation of the two NICs.
② In the computer system, install the Turbo Linux operating system and configure the first NIC (IO = 0x300). The system automatically identifies the nic iobase = 0x300 by default, use the ping command to test the NIC status.
③ To reduce possible problems during startup, the Linux kernel does not automatically detect multiple NICs. If you need to install multiple NICs on the server, for the system that has compiled the NIC driver into the kernel, you need to install the NIC Driver in "/etc/lilo. the conf file specifies the parameter information of each Nic. For a system that does not compile the NIC driver into the kernel but dynamically loads it as a module. modules file.
④ Install the second Nic and add the configuration information in "/etc/lilo. conf" by passing the startup parameter information to the kernel through the LILO program. For the ISA card, edit the "/etc/lilo. conf" file and add the following content: ether = 10, 0x320,0, 0, eth1.
The first four parameters are numbers, and the last parameter is the device name. All numeric variables can be freely selected. If you ignore or set it to 0, the core automatically checks the parameter variables of the device or uses the default value. The first parameter indicates the interrupt request channel allocated to the device. By default, the core automatically detects the IRQ channel of the device. The second parameter variable is used to specify the Basic I/O address of the device. Similarly, if the value is 0, the core automatically detects the I/O address of the device. The remaining two parameter variables have different meanings for different devices. For Shared Memory NICs, they are used to define the starting and ending points of the shared memory area. For other NICs, they use the first parameter to set the debugging level of the information. Numbers 1 to 7 indicate that the debugging level is gradually increased, the number 8 indicates that information debugging is disabled, and 0 indicates that the default value is used.
⑤ Restart the machine.
⑥ Use Turbonetcfg to add eth1 and configure network parameters of the NIC, such as IP addresses and gateways.
7. Restart the machine and run the ping command to test the NIC status.
⑧ The Ifconfig command is used to display the Interface status.
  
Ii. correct IP Masq settings
  
1. Check whether the Linux kernel supports IP Masq.
Check whether the Linux kernel supports IP Masquerade. If your Linux version supports the following features:
IPFWADM/IPCHAINS, IP forwarding, IP masquerading, IP Firewalling
You do not need to re-compile the Linux kernel. If you are not sure, run the following command to perform a test:
# Ls/proc/sys/net/ipv4
If the following file exists, Linux supports IP Masquerade: "ip_forward", "ip_masq_debug", "ip_masq_udp_dloose", and "ip_always_defrag ".
2. assign a private IP address to the Intranet
Private IP addresses are used for enterprise internal networking based on TCP/IP technology. They are allocated by The Internet Assigned Numbers Authority (IANA). The author uses The following address: 192.168.0.0/24.
3. Create a file/etc/rc. d/rc. firewall and edit the management rule.
# Rc. firewall-Initial simple ip Masquerade test for 2.1.x and 2.2.x kernels
# FORWARD_IPV4 = true
Echo "1">/proc/sys/net/ipv4/ip_forward
# CRITICAL: Enable automatic IP defragmenting since it is disabled by default
# In 2.2.x kernels. This used to be a compile-time option but the behavior was changed in 2.2.12
Echo "1">/proc/sys/net/ipv4/ip_always_defrag
# MASQ timeouts 2 hrs timeout for TCP session timeouts
#10 sec timeout for traffic after the TCP/IP "FIN" packet is already ed
#160 sec timeout for UDP traffic (Important for Masq 'ed ICQ users)
/Sbin/ipchains-M-S 7200 10 160
# Enable simple IP forwarding and Masquerading
/Sbin/ipchains-P forward DENY
/Sbin/ipchains-A forward-I eth0-s 192.168.0.0/24-j MASQ
* Comment that interface eth0 is a public IP Address (Registered IP Address );
After editing the rules of the/etc/rc. d/rc. firewall file, you can run the following command to change the File Permission: # chmod 700/etc/rc. d/rc. firewall.
4. Load Firewall to the Startup Script
After the Firewall rule is specified, restart the computer system. You can run it manually or modify the system startup script in the System for Automatic execution.
Manually run the following command at the System Command Prompt: #/etc/rc. d/rc. firewall.
To edit the startup script, add the following content to the/etc/rc. d/init. d file:/etc/rc. d/rc. firewall.
After running IP Masq, run the ping command to test the NAT network function and check whether IP Masq is running properly.
The following is the system route table after Linux IP Masq is running properly.
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.