美文网首页
CentOS7 iptables 配置8080端口

CentOS7 iptables 配置8080端口

作者: 赛亚人之神 | 来源:发表于2020-03-23 13:12 被阅读0次

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

相关文章

网友评论

      本文标题:CentOS7 iptables 配置8080端口

      本文链接:https://www.haomeiwen.com/subject/gaqwyhtx.html