Use IP link to build a Linux Firewall

Source: Internet
Author: User

Although the Linux operating system has many advantages and its security is high, you should not generate a false sense of security, because the security of your Linux system may still be compromised. Now let's take a look at how to build a Linux system firewall by using IP chain IPchains to protect your system from infringement.
Let's assume that you already have some basic Internet knowledge. It should be said that it is very useful to be familiar with terms such as IP addresses, TCP ports, and network data transmission. It is also necessary to have a general understanding of the firewall.
■ Command:
We need to establish a series of rules so that the IP chain can enter the network paths that come and go. Each rule is placed in one of the three Chains: The input chain for storing input data, the output chain for storing output data, and the transmission chain.
Each time you add a rule, you must start with the IP link and add some or all of the following steps. Append, Delete, Insert, and Replace, it also indicates the link on which the rule command should be added and how to add it. At the time of addition, start with-A,-D,-I, or-R. These letters are followed by A chain name input chain or an output chain ).
When you want to use the INSERT command, you must specify the line number after the chain name at the location where you want to add the command.
When using the replacement command, you must specify the replaced line number. When using the DELETE command, you must also specify the deleted line number.
When using the delete option, you do not need to enter anything after the row number. You only need to type ipchains-L to find the row number of the command.

■ Protocol ):
Here you need to specify a specific protocol for each rule command. In most cases, the TCP/IP protocol is used.
Maybe you don't want your computer to respond to the Ping signal from another computer. To achieve this, you need to specify the ICMP Internet Control Packet protocol ). When specifying a specific protocol, use the-p command, for example,-p icmp.
■ Source ):
The source can determine the path from a specific IP address and the port using the-s command. If you know a standard IP address, you can directly use the IP address, or simply specify a domain name such as www.ccidnet.com ). If you want to specify any address, use 0.0.0.0/0.
You can specify a port, for example, 110, or pop3, after the IP address. You can use colons to separate two port numbers so that you can specify a series of ports. For example:
-S mail.mailserver.com pop3
-S 127.0.0.1 139: 164
■ Objective (Destination ):
The usage is the same as the source address. You only need to specify the destination address and port.
■ Jump to Jump ):
The last option we need to know is the-j command. This command tells the firewall what steps should the firewall take if a rule command matches the data being entered. In most cases, this step is accepted or rejected. For example, if you want to reject a group of data that matches the command, the firewall jumps to the drop button. If a group of data does not comply with a command rule, the data goes forward to the next command. If no rule matches this set of data, the data will be rejected by default.
Of course, there are some other options and commands that can be used together with IP link commands. For more information, enter ipchains-h in the command line.

Create a firewall
The core part of building a Linux system firewall is to keep other servers close to your system while approaching the server you want to access. Here we provide some advice.
First, try to use the-I command for all "deny" rules when creating your firewall. When a rule blocks a group of data, a line of information is generated and added to the variable/record/core program/information record of your core program information ). Once you read this file, you can see why a group of data is blocked. A record details the steps taken, explains a rule source destination chain, source address and port, and destination address and port, so you can use this information to adjust the firewall. You can own anything in the way you want, and then you no longer need the-I command.
Second, a firewall can block all inbound Syn data. Syn data is a data group used to start a link, but they should not appear on most desktop systems. You can use the-y command as follows:
Ipchains-I input 1-p tcp-y-j DENY
You can also use the following command to Block ICMP data:
Ipchains-I input 2-p icmp-j DENY
Putting these two rules at the beginning ensures that the system does not receive the data at will. Next, block some common server ports such as ftp, telnet, smtp, and pop3:
Ipchains-A input-p tcp-s 0.0.0.0/0 ftp DENY
Ipchains-A input-p tcp-s 0.0.0.0/0 telnet DENY
Ipchains-A input-p tcp-s 0.0.0.0/0 smtp DENY
Ipchains-A input-p tcp-s 0.0.0.0/0 pop3 DENY
Ipchains-A input-p tcp-s 0.0.0.0/0 nntp DENY
If a problem occurs when connecting to the server where the email is sent, you can insert a rule before the smtp and pop3 DENY rules to disable the so-called DENY rules. However, it is necessary to ensure the clarity of this rule, because this will invalidate the DENY rule. Generally, specifying an IP address is a good practice:
Ipchains-I 3 input-1-p tcp-s mail.mailserver.com pop3-j ACCEPT
Ipchains-I 4 input-1-p tcp-s mail.mailserver.com smtp-j ACCEPT
You can replace the domain name "mail.mailserver.com" with the address of the server you sent the mail. This can be done for a new server or any FTP website with a link that is difficult.
Although these rules are basic, they help to build a secure and effective firewall. We can detect the security and effectiveness of firewalls on websites like Gibson Research Center (http://www.grc.com) and DSL Reports (http://www.secure-me.net. The above two websites can provide port queries on the Internet for free. Once a useful rule is found, use the ipchain-save command to save the rule to a file.
You can use this file to save the rules when you restart the system. Type ipchains-save/etc/ipchains. rules to save the firewall settings. When you keep firewall settings after restarting your system, type ipchains-restore/etc/ipchains. rules. When your system is powered off or restarted, the Linux system does not automatically save the settings.


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.