CentOS7 iptables 配置8080端口

vim /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7900 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8850 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT

iptables 为我们预定义了 4 张表,分别是 raw, mangle, nat, filter. 每个表对应不同的功能.
filter 负责过滤功能: 比如允许那些 ip 访问,允许访问哪些端口等
常用参数: 使用 -t 指定查询的表,默认查询 filter 表

--table -t table    table to manipulate (default: `filter')
--list    -L [chain [rulenum]]
                List the rules in a chain or all chains
--verbose   -v      verbose mode
--numeric   -n      numeric output of addresses and ports
--flush   -F [chain]        Delete all rules in  chain or all chains

--protocol  -p proto    protocol: by number or name, eg. `tcp'

--source    -s address[/mask][...]
                source specification
--destination -d address[/mask][...]
                destination specification
--in-interface -i input name[+]
                network interface name ([+] for wildcard)
--jump  -j target
                target for rule (may load target extension)
image.png

iptables -L INPUT -v: in, out, source, destination 这些属性显示的是经过转义的字符, 加上选项 -n, 显示未经过转义的格式

image.png

iptables -L INPUT -vn
image.png

target 属性表示 chain 的动作,这里表示接受 ACCEPT

iptables -L INPUT -vn --line

image.png

增:
--append -A chain Append to chain

--insert -I chain [rulenum]
Insert in chain as rulenum (default 1=first)

命令语法:iptables -t 表名 -A 链名 匹配条件 -j 动作
示例:iptables -t filter -A INPUT -s 192.168.1.146 -j DROP

命令语法:iptables -t 表名 -I 链名 匹配条件 -j 动作
示例:iptables -t filter -I INPUT -s 192.168.1.146 -j ACCEPT

命令语法:iptables -t 表名 -I 链名 规则序号 匹配条件 -j 动作
示例:iptables -t filter -I INPUT 5 -s 192.168.1.146 -j REJECT

删:
--delete -D chain Delete matching rule from chain
--delete -D chain rulenum
Delete rule rulenum (1 = first) from chain
--flush -F [chain] Delete all rules in chain or all chains

命令语法:iptables -t 表名 -D 链名 规则序号
示例:iptables -t filter -D INPUT 3

命令语法:iptables -t 表名 -D 链名 匹配条件 -j 动作
示例:iptables -t filter -D INPUT -s 192.168.1.146 -j DROP

命令语法:iptables -t 表名 -F 链名
示例:iptables -t filter -F INPUT

命令语法:iptables -t 表名 -F
示例:iptables -t filter -F

改:
--replace -R chain rulenum
Replace rule rulenum (1 = first) in chain

命令语法:iptables -t 表名 -R 链名 规则序号 规则原本的匹配条件 -j 动作
示例:iptables -t filter -R INPUT 3 -s 192.168.1.146 -j ACCEPT

改(chain)的策略:
--policy -P chain target
Change policy on chain to target

命令语法:iptables -t 表名 -P 链名 动作
示例:iptables -t filter -P FORWARD ACCEPT

查:
--list -L [chain [rulenum]]
List the rules in a chain or all chains
--list-rules -S [chain [rulenum]]
Print the rules in a chain or all chains

iptables -t FILTER -L INPUT -nv --line
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 两台主机两个路由设备通信 现有主机A和主机B,且中间有两个路由设备连接,主机A的IP地址为192.168.1.10...
    JevonWei阅读 5,160评论 0 3
  • -------------------安装常用软件------------------- #yum-yinstal...
    搬砖中年人阅读 3,122评论 0 0
  • 前言 一个局域网中,主机之间互联,其中只有一台主机可以上网,其他主机想要上网怎么办?答:使用SNAT。 情景模拟 ...
    VoidKing阅读 12,597评论 3 4
  • 转自:https://blog.csdn.net/sdd220/article/details/77716824/...
    野时光阅读 4,181评论 0 0
  • 师父语:六祖说得好“佛法在世间,不离世间觉”,其实人世间的一举一动或者是某一场苦和乐都可能是使我们大彻大悟的那个开...
    明距阅读 2,817评论 1 1