centOS Linux 设置防火墙命令

1.查看防火墙状态。
(1) service iptables status
(2) systemctl status iptables
(3) service firewalld status
(4) systemctl status firewalld
1、2命令适用于 centOS 6 及一下版本。
3、4命令适用于 centOS 7。
2.停止防火墙(重启后会恢复)
(1) service iptables stop
(2) systemctl stop iptables
(3) service firewalld stop
(4) systemctl stop firewalld
1、2命令适用于 centOS 6 及一下版本。
3、4命令适用于 centOS 7。
3.开启防火墙(重启后会恢复)
(1) service iptables start
(2) systemctl start iptables
(3) service firewalld start
(4) systemctl start firewalld
1、2命令适用于 centOS 6 及一下版本。
3、4命令适用于 centOS 7。
4.重启防火墙
(1) service iptables restart
(2) systemctl restart iptables
(3) service firewalld restart
(4) systemctl restart firewalld
1、2命令适用于 centOS 6 及一下版本。
3、4命令适用于 centOS 7。
5.永久关闭防火墙
永久性生效,重启后不会复原(使用该命令后需要重启后才生效

开启:
1.chkconfig iptables on
2.systemctl enable firewalld.service
关闭:
1.chkconfig iptables off
2.systemctl disable firewalld.service
重启系统

reboot//重新启动系统

在 CentOS 7
暂时开放FTP服务

# firewall-cmd --add-service=ftp

永久开放FTP服务

# firewall-cmd --add-service=ftp --permanent

永久关闭

# firewall-cmd --remove-service=ftp --permanent
success

讓設定生效

# systemctl restart firewalld

檢視設定是否生效

# iptables -L -n | grep 21
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:21 ctstate NEW

檢查防火牆狀態


# firewall-cmd --state
running

# systemctl stop firewalld
# firewall-cmd --state
not running


# firewall-cmd --list-all
public (default)
  interfaces:
  sources:
  services: dhcpv6-client ftp ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

在 FirewallD 的服務名稱

# firewall-cmd --get-service
amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https

查詢服務的啟用狀態

# firewall-cmd --query-service ftp
yes
# firewall-cmd --query-service ssh
yes
# firewall-cmd --query-service samba
no
# firewall-cmd --query-service http
no

自行加入要開放的 Port

# firewall-cmd --add-port=3128/tcp
# firewall-cmd --list-all

public (default)
interfaces:
sources:
services: dhcpv6-client ftp ssh
ports: 3128/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值