Simple firewall construction and traffic statistics
Source: Internet
Author: User
Article title: simple firewall construction and traffic statistics. 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.
The firewall is basically designed to prevent others from accessing your network and control the inbound and outbound information on the network. one end of the firewall is connected to an external network (through a real IP address ), the other end is connected to the internal network (Virtual IP address), which isolates your internal network from the external network. The Firewall becomes the only channel to enter your internal network, therefore, any incoming and outgoing information must go through the firewall and then determine whether it can pass through the firewall. Therefore, the security is further guaranteed.
In addition, this article also introduces two heavyweight software to facilitate monitoring of network traffic and past network packets, which should also be one of the functions of the firewall.
2. types of firewalls
2.1 Packet Filter
The packet filter function filters each packet based on the set rules to check whether the packet is allowed to be transmitted or rejected. the packet filter exists at the network layer and does not affect the data in the packet. In RedHat Linux, there is an ipchains suite (included in more than 6.0), which can be used as a data packet filter.
2.2 Proxy firewils)
The proxy server, also known as the application gateway, allows indirect access to the Internet through the firewall.
3. start building a firewall
Network Address Translation (NAT)
As the development of Internet connection is booming, the number of computers is also increasing rapidly, leading to the current shortage of IP addresses, which is hard to find. Therefore, we need to use virtual IP addresses to solve this problem, we believe that virtual IP addresses will become a trend in the future. A specific IP address is retained on the network for use by a private virtual network. these three IP addresses are not found on the real network. these virtual IP addresses are:
Class A 10.0.0.0 ~ 10.20.255.255
Class B 172.16.0.0 ~ 172.31.255.255
Class C 192.168.0.0 ~ 192.168.255.255
3.1 view the network card status
First, you must have two network card interfaces, one external (using real IP) eth1, and one internal (using virtual IP) eth0.
Ifconfig-
The network card setting value appears to check whether two network cards are captured.
Note that the setting values of eth0 and eth1 are the opposite, that is, eth0 corresponds to the real IP address and eth1 corresponds to the virtual IP address, if this is the case, you must modify it. Otherwise, the network cannot be connected, which will be mentioned below.
It is possible that the system may be stuck on the screen when the system is started. if this is the case, we recommend that you remove a network card and reboot the system.
Ifconfig-A | more
View the currently started network card interface. The status is all set.
3.2 configuration file/etc/sysconfig/network
If there is only one network card, we will install another network card manually. first, switch to the/etc/sysconfig directory and there is a file network with the following content:
The FORWARD_IPV4 parameter must be set to yes to enable IP disguised conversion.
3.3/etc/sysconfig/network-scripts/ifcfg-eth1
The following files are displayed in the/etc/sysconfig/network-scripts directory:
At present we should pay attention to the ifcfg-eth0, ifcfg-eth1 these two files, after you install it only ifcfg-eth0 this file, and no ifcfg-eth1. First Copy the ifcfg-eth0 to the ifcfg-eth1 and execute
Cp ifcfg-eth0 ifcfg-eth1
The ifcfg-eth1 for external network card settings, according to their own device to modify, its content is:
The first line specifies the network card interface: eth1
Row 3 specifies the broadcast address: 192.192.73.255
The fourth row specifies the IP address: 192.192.73.35
The network mask specified for the fifth line is 255.255.255.0.
The sixth row specifies the network number: 192.192.73.0
Row 7 specifies whether to enable the network card interface after the instance is started.
Here we directly modify the profile ifcfg-eth0 as an internal virtual network card interface, the content is:
The first line specifies the network card interface: eth0
The broadcast address specified in row 3 is 192.168.1.255.
The fourth row specifies the IP address: 192.168.1.1
The network mask specified for the fifth line is 255.255.255.0.
The network number specified in row 6 is 192.168.1.0.
Row 7 specifies whether to enable the network card interface after the instance is started.
In the internal network we specified here, the network number is 192.168.1.0 and the broadcast number is 192.168.1.255. Therefore, the truly available virtual ip address is 192.168.1.1 ~ 192.168.1.254.
3.5 start the NIC
Close startup
Run ifconfig eth0 up ifconfig eth0 down
Run ifconfig eth1 up ifconfig eth1 down
3.6 set route table
After the preceding configuration file is set and started, we must create a route for the two networks ).
In this way, two network cards are installed, and eth1 serves as the external network card (real IP address) and eth0 serves as the internal network card (Virtual IP address ).
3.7 test
Using eth1 as the internal network interface, its virtual IP address is 192.168.1.0 ~ 192.168.1.255, because the first is the network number and the last is the broadcast number, the available virtual IP address is 192.168.0.1 ~ 192.168.255.254, we set the gateway as 192.168.0.1, the subnet mask as 255.255.255.0, and 192.168.1.2 ~ The IP addresses of 192.168.1.254 are allocated to internal machines, and then the internal machines can communicate with each other ('ping'). However, to connect them out, another step is required, that is to use a program, ipchains, to achieve this goal. To solve the problem above, if you want to connect an internal machine to an external network, run the following command:
It can be specified in two forms, expressed by full name or abbreviated form.
-- Add-A: add new ipchains rules
-- Delete-D: delete the first ipchains rule or an ipchains rule.
-- Insert-I inserts a new ipchains rule. you need to specify the number in the rule to insert the rule. if the number is 1, it indicates the first rule.
-- Replace-R replaces the selected rule and replaces the number in the rule.
-- List-L lists the selected ipchains rules. If no rules are specified, all rules are listed.
-- Flush-F clears an ipchains rule (for example, input, output, and forward), which is equivalent to deleting the rule.
-- Zero-Z returns the packets and bittuples in all rules to zero. It can also specify the-L, -- list (list) option to list the previous data first, then list the data for the return to zero.
-- Check-C: check whether a packet violates the rules. this is a very useful test, including-s (source),-d (destination),-p (protocol ), -I (interface) is even more necessary.
-- New-N generates a new user-defined rule ).
-- Delete-chain-X: delete a user-defined rule. If no parameter is specified, it will define the rule.
-- Policy-P: only input, forward, and output can set the target policy.
-- The masquerade-M option can be used to view the current camouflage connection status (the-L option must be added), or to set the kernel camouflage parameter (-S option ).
-- Set-S to set the camouflage stop time variable
-- Help-h: list the descriptions of command syntax.
4.3 ipchains parameter options
It can be specified in two forms, expressed by full name or abbreviated form.
Use '! 'Define the opposite meaning: exclamation point '! 'Has the meaning of 'not', and many options can be added '! .
Example:-s! Localhost
Note: it indicates that all source addresses except localhost can be used.
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