Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to configure Firewall iptables with linux

Shulou Source: shulou.com Published: 2022-06-01 08:09:19 10月02日 Update

How to configure firewall iptables with linux, I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

A detailed example of iptables

The code is as follows:

/ etc/init.d/iptables start starts iptables

Initialize iptables and delete previous rules

The code is as follows:

Iptables-F

Iptables-X

Iptables-Z

Iptables-F-tnat

Iptables-X-tnat

Iptables-Z-tnat

Allow SSH to enter, or you won't be able to connect later

The code is as follows:

Iptables-AINPUT-pTCP--dport22-jACCEPT

Set the rules for default entry and exit

The code is as follows:

Iptables-PINPUTDROP

Iptables-POUTPUTACCEPT

Iptables-PFORWARDACCEPT

Iptables-AINPUT-ilo-jACCEPT

Iptables-AINPUT-mstate--stateESTABLISHED,RELATED-jACCEPT

Load the corresponding module

The code is as follows:

Modprobeip_tables

Modprobeiptable_nat

Modprobeip_nat_ftp

Modprobeip_conntrack

Modprobeip_conntrack_ftp

Configure default forwarding rules

The code is as follows:

Iptables-tnat-PPREROUTINGACCEPT

Iptables-tnat-PPOSTROUTINGACCEPT

Iptables-tnat-POUTPUTACCEPT

Allow private network connection

The code is as follows:

Name of iptables-AINPUT-i private network Nic (such as eth2)-jACCEPT

Enable forwarding

The code is as follows:

Echo "1" > / proc/sys/net/ipv4/ip_forward

Configure the source NAT to allow the intranet to access the Internet through the host nat, which is called network sharing.

The code is as follows:

Iptables-tnat-APOSTROUTING-s intranet Nic name-o extranet Nic name-jMASQUERADE

Map the FTP server to the public network

The code is as follows:

Iptables-tnat-APREROUTING-ptcp-d58.222.1.3--dport21-jDNAT--to192.168.0.211:21

It's over. Don't forget to save it.

The code is as follows:

Serviceiptablessave

The gateway of 192.168.0.211 should be set to host 192.168.0.1. That's it.

After reading the above, have you mastered how to configure firewall iptables with linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Code configuration network card rules firewall fire prevention host content method more problem helpless for this function reason example this skills server module Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi Docker Apple macOS