IPtables firewall usage skills

Source: Internet
Author: User
IPtables firewall usage tips: Recently, a small LINUX server was set up. because LINUX machines need to be used as soft routers, let's talk about the experience of using IPtables firewall. Iptables is very powerful. For example, IP forwarding and disguised defense against DoS, scanning and sniffing attacks. I will not elaborate on it here

IPtables firewallUseTips:

Recently, a small LINUX server was set up. because LINUX machines need to be used as soft routers, let's talk about the experience of using IPtables firewall.IptablesIs very powerful. For example, IP forwarding and disguised defense against DoS, scanning and sniffing attacks. My system environment is not described here. The simple configuration is as follows:

Redhat 7.2

Adsl 2 m

8139 fast Nic

1. how to use the soft routing function in linux:

Speaking of this, you may think, as long as you are in/etc/rc. d/rc. add cat 1>/proc/sys/net/ipv4/ip_forward to local, so that linux has the ip_forward function. However, you will find that other computers in your Lan cannot share the Internet. Why? When you only have one public ip address, you must use the iptables IP address camouflage function to disguise the IP address as your public IP address. How can I implement the IPtables firewall? You can:

Iptables-t nat-a postrouting-o ppp0-j MASQUERADE

In this way, you can disguise the IP address you sent out as the IP address of ppp0 (because my ADSL can be modified if it is different ).

2. Enable http service and external service without opening the port

I don't want to open my port, but I want to enable the http service on my computer and provide external services. Because you do not want to open ports other than 80, you can do this:

Iptables? P input? J DROP

We use-P to intercept all the communication, and then you can write as follows to allow which ports can be used:

Iptables? A input? P tcp? Dport 80? J ACCEPT

You can add the port you want to open in this format as appropriate. of course, if you feel that this is not a good management, you can also create an iptables table. you can do this:

Iptables? N test (create a test table)

Iptables? A test DROP

Iptables? A test? P tcp? Dport 80? J ACCEPT (allow access to port 80)

Iptables? A input? J test

Iptables? A output? J test

Iptables? A forward? J test

(These three values indicate that the input output forward is set according to test)

3. set up an ftp service on an intranet computer

What should I do if I set up an ftp service on an intranet computer? This requires another powerful function of iptables-Port ing. you can do this:

Iptables-t nat-a prerouting-p tcp-m tcp -- dport 25-j DNAT -- to-destination

192.168.0.6: 21

Iptables-t nat-a postrouting-s 192.168.0.0/24-d 192.168.0.6-p tcp-m tcp --

Dport 25-j SNAT -- to-source 192.168.0.1

In the above two sentences, port 25 of the server is mapped to 192.168.0.6.

4. don't want others to PING me

This is about one of the most commonly used iptables firewalls. you can write this sentence in iptables:

Iptables-a input-p icmp -- icmp-type echo-request-I ppp0-j DROP

If you have created a new test table, you can write it like this.

Iptables-A test-p icmp -- icmp-type echo-request-I ppp0-j

DROP

In this case, PING is not allowed because the icmp protocol is used. Because icmp does not have a port, you do not need to specify a port.

Okay! This is the basic usage of IPtables firewall. Here we will introduce several commands commonly used in iptbales.

Iptables? F. clear all iptables rule settings.

/Sbin/iptables-save> iptables? Save

In this way, save your rules. Because all the rules you set will not be saved after you restart them, you must write a script to enable it to run on startup. In this way, you can use this command to save your rules and enable them to run automatically upon startup. The IPtables firewall usage tips are introduced here. For other usage methods, refer to other information on this site ~

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.