Linux-based Router and firewall configuration

Source: Internet
Author: User
Article Title: Linux-based Router and firewall configuration. 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.
Currently. Network Operating System Linux has become the operating system of computer technology professionals. Through simple installation, technicians can obtain multiple network services provided by Linux, such as Domain Name Service, email, anonymous FTP service, etc. It also provides the Xwindows System of the graphics workstation. The latest Linux7.2 has all the functions of the network server. Here, the company wants to talk about the use of Linux on the other hand, that is, connecting Linux as a router to two different network segments and configuring a firewall on it, based on its own work experience, to achieve network access control and traffic statistics.
To enable a Linux PC to have a router function, you must first configure the hardware. Assume that a Router PC is installed with a Linux system and is equipped with two NICs, each of which is connected to a different CIDR block. The Router forwards IP packets between the two CIDR blocks. To prevent two NICs from being interrupted, the NIC driver needs to set the interruptions to different values. In practice, our company sets the disconnections and I/O addresses as 3, 0x300 H and 4, 0x320 H respectively.
After the hardware configuration is complete, you must configure the software. In normal installation mode, the Linux system does not have the backup router function. Therefore, you must reinstall the Linux kernel. For Linux of Slackware, The Kernel configuration process is 1. # cd/usr/src/linux.
/* Enter the source code target of Linux */
2. # make config
/* Configure compilation options */
In this step, the system provides some options during the compilation process for you to choose based on your actual situation. For uncertain options, you can select the system default value. The following prompt appears in the network compilation query:
Network firewall [y/n/N]?
/* Does the Kernel support firewall */
......
TCP/IP networking [n/y/Y]?
/* Whether the host is connected to the TCP/IP Network */
IP: forwarding/gatewaying [n/y/Y]?
/* Whether the host forwards the database or acts as a gateway */
......
IP: firewalling [y/n/N]?
/* Set firewall in TCP/IP Network */
IP: firewall packet logging [y/n/N]?
/* Whether to register data packets on the firewall */
......
IP: accounting [y/n/N]?
/* Whether to account for data packets */
IP: optimize as router not host [y/n/N]?
/* Set the host to a vro */
......
IP: multicats routig [y/n/N]?
/* Whether the router broadcasts route information externally */
Because we want to configure this host as a router and set a firewall on it, we choose "y" for these options ".
3. # make dep
/* Prepare for compilation based on the Compilation options */
4. # make zlmage
/* Start to compile the kernel and name the compiled Kernel File zlmage */
The compiled kernel is stored in the "/usr/src/linux/arch/i386/boot" directory. After the system's original kernel backup, you can copy the file to the root directory and change it to "vmlinuz". Run "lilo" to make it effective at the next startup.
After restructuring the kernel, you need to set the TCP/IP of the two NICs so that they can effectively connect two different network segments and forward IP packets in the two network segments. Set the steps to (the parameters are shown in the figure ):
1. For NE2000 compatible NICs, modify the "/etc/rc. d/rc. modules" file;
/Sbin/modprobe ne io = 0x320, 0 x
/* Identify two NICs */
2. Modify the "/etc/rc. d/rc. inetl" file and set the IP address and mask of the two NICs and the route information to the two NICs;
IPADDR = "202.207.0.27"
NETWORK = "202.207.0.0"
BROADCAST = "202.207.0.255"
IPADDR1 = "202.207.7.2"
NETWORK1 = "202.207.7.0"
BROADCAST1 = "202.207.7.255"
NETMASK = "255.255.255.0"
/Sbin/ifconfig eth0 $ {IPADDR} broadcast $ {BROADCAST} netmask $ {NETMASK}
/Sbin/ifconfig eth1 $ {IPADDR1} broadcast $ {BROADCAST1} netmask $ {NETMASK}
/Sbin/route add-net $ {NETWORK} netmask $ {NETMASK} eth0
/Sbin/route add-net $ {NETWORK1} netmask $ {NETMASK} eth1
3. modify "/etc/rc. d/rc. in the inet2 file, open a comment on "Routed Server" so that it can exchange route information with other routers and forward IP packets.
# Start the Routed server
If [-f $ {NET}/routed]; then
Echo-n "routed"
$ {NET}/routed-g-s
/* Start the program */
Fi
4. Add a line to the "/etc/lilo. conf" file so that it can identify the second nic at startup.
Append = "ether = 320 x, ethl"
After completing the above settings, restart the computer. The system will identify two NICs and follow "/etc/rc. d/rc. the description in the intel file sets the IP address and mask of the NIC. After the startup is complete, enter the system as the root user, and enter the following command to view the nic and route information.
# Ifconfig/* display the NIC details */
# Route
/* Display the system route table */
Our company once connected the PC in the LAN of a company's machine room to the local education network through a Linux router, and further connected to the Internet through the Local Education Network. In addition, I have configured a firewall on the Linux router. Practice has proved that the firewall effectively controls access to illegal IP addresses by internal staff of the company, and successfully records the network traffic of each IP address, providing a basis for billing and network management. For Linux firewall configuration, you can use simple commands one by one, or write shell programs to automatically execute them in the startup directory of the system. The command format is very simple. The example is as follows:
# Ipfwadm-
/* Account for all data packets sent through the vro */
# Ipfwadm-I-a accept-S 162.105.0.0/16
/* Accept all data packets from the 162.105.0.0 Network */
# Ipfwadm-I-a deny-S 159.226.0.0/16
/* Discard all data packets from the 159.226.0.0 Network/
# Ipfwadm-O-a reject-S 210.32.0.0/12
/* Discard all data packets sent to the 210.32.0.0 network and send the rejection packet to the requester */
You can configure the firewall as needed to achieve the desired effect. Or complete the security configuration with the assistance of the Security intermediary.

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.