centos7 关于firewalld 与 iptables 防火墙的 “爱恨情仇”

centos7 默认自带防火墙firewalld

关于firewalld防火墙的配置文章如下:
Linux防火墙放行端口


某些人非在 centos7 上用 iptables 不可

先喷两句:
说某些人,非得把老掉牙的 centos6 上的防火墙 iptables 搞到 centos7 上,
脑浆子进水,绝对的脑残
坚决抵制,跟这种人没什么好说的,却也没办法


这不今天的事儿,其实之前有一次面试也被问到过iptables,这些centos6老玩家就喜欢TMD问iptables规则,说起今天的事,其实也真的怪自己,老大说开个白名单,开就完事了,我云里糊涂的搞错了一条命令,准确说是自己技不如人,被一篇文章坑死了


再来喷一波,这个csdn blog有些博主还行,分享文章与人方便自己方便,帮助他人,但是有些博主是真的狗,特么误导别人,真还有傻子上当了,对那个傻子就是我
那篇文章说 使用 iptables --flush 是更新防火墙规则,去他大爷的,滚吧,狗屎,那条命令的真正含义是清除防火墙所有规则,我竟然傻X的信了他的文章,然后搞的无法连接服务器了,幸好是测试环境,要是生产环境就完犊子了
明天那运维老哥会直接在他机房本地登入服务器,重新配置iptables规则,等他搞完,我再重新搞白名单

喷了几波,书回正传

那个运维老哥是centos6老玩家,他做了啥操作呐?
直接在centos7上关停、禁用firewalld防火墙

systemctl stop firewalld
systemctl disable firewalld

然后安装 iptables、iptables-services服务

yum install -y iptables iptables-services

然后启动iptables服务,并设置开机自启

service iptables status
service iptables start
service iptables enable

正确的 iptables 开白名单方式

iptables -L -n && \
iptables -A INPUT -p tcp -m tcp --dport 1234 -j ACCEPT && \
service iptables save && \
iptables -L -n && \
cat /etc/sysconfig/iptables

我就是手欠啊,信了那个狗屎博主的当了,配置完规则后,加了一条 iptables --flush,我原以为就是是更新规则,实际上呐,狗屎,被坑大了

下面我们来深入一下 iptables 详细用法

[root@test ~]# iptables --help
iptables v1.4.21

Usage: iptables -[ACD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)

Commands:
Either long or short options are allowed.
  --append  -A chain            Append to chain
  --check   -C chain            Check for the existence of a rule
  --delete  -D chain            Delete matching rule from chain
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain
  --insert  -I chain [rulenum]
                                Insert in chain as rulenum (default 1=first)
  --replace -R chain rulenum
                                Replace rule rulenum (1 = first) in chain
  --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
  --flush   -F [chain]          Delete all rules in  chain or all chains
  --zero    -Z [chain [rulenum]]
                                Zero counters in chain or all chains
  --new     -N chain            Create a new user-defined chain
  --delete-chain
            -X [chain]          Delete a user-defined chain
  --policy  -P chain target
                                Change policy on chain to target
  --rename-chain
            -E old-chain new-chain
                                Change chain name, (moving any references)
Options:
    --ipv4      -4              Nothing (line is ignored by ip6tables-restore)
    --ipv6      -6              Error (line is ignored by iptables-restore)
[!] --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)
  --goto      -g chain
                              jump to chain with no return
  --match       -m match
                                extended match (may load extension)
  --numeric     -n              numeric output of addresses and ports
[!] --out-interface -o output name[+]
                                network interface name ([+] for wildcard)
  --table       -t table        table to manipulate (default: `filter')
  --verbose     -v              verbose mode
  --wait        -w [seconds]    maximum wait to acquire xtables lock before give up
  --wait-interval -W [usecs]    wait time to try to acquire xtables lock
                                default is 1 second
  --line-numbers                print line numbers when listing
  --exact       -x              expand numbers (display exact values)
[!] --fragment  -f              match second or further fragments only
  --modprobe=<command>          try to insert modules using this command
  --set-counters PKTS BYTES     set the counter during insert/append
[!] --version   -V              print package version.
[root@test ~]#

所以,可以清晰的看到

--flush -F [chain] Delete all rules in chain or all chains
意思就是删除所有规则

真是气死个人,有些文章真的是害人匪浅啊


所以,也是吸取教训,从今以后知之为知之,不懂就先 --help,先确认再干活
这年头啥都得学,你所在的团队决定了你用什么,工作仅仅是工作,你能有什么办法
侧面来说,你技术不行,还不到家
以后做事,谨慎小心,跟老大确认完再干,老大不回就等着,不要善做主张
挣人家的钱不好挣
喷归喷,气归气
有什么办法,把自己搞强大了,学到的都融会贯通
讲真的,感觉真的是没有追求可言,给钱就干,干呗,也就这么着了
还得自己多下功夫,等你优秀了等你当老大了,你说用啥那就用啥,你想用啥就用啥
在这之前,只能学习,努力学认真学,都学会

猜你喜欢

转载自blog.csdn.net/frdevolcqzyxynjds/article/details/121483554