Firewall 配置
在 CentOS 7暫時開放 ftp 服務# firewall-cmd --add-service=ftp永久開放 ftp 服務# firewall-cmd --add-service=ftp --permanent
永久關閉# firewall-cmd --remove-service=ftp --permanentsuccess讓設定生效# systemctl restart firewalld檢視設定是否生效# iptables -L -n | grep 21ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW
檢查防火牆狀態# firewall-cmd --staterunning# systemctl stop firewalld# firewall-cmd --statenot running# firewall-cmd --list-allpublic (default) interfaces: sources: services: dhcpv6-client ftp ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules:在 FirewallD 的服務名稱# firewall-cmd --get-serviceamanda-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 ftpyes# firewall-cmd --query-service sshyes# firewall-cmd --query-service sambano# firewall-cmd --query-service httpno自行加入要開放的 Port# firewall-cmd --add-port=3128/tcp --permanent# firewall-cmd --list-allpublic (default) interfaces: sources: services: dhcpv6-client ftp ssh ports: 3128/tcp masquerade: no forward-ports: icmp-blocks: rich rules:
开放地址段
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -s 192.168.100.1/24 -j ACCEPT
启用NAT
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --to-source 106.3.226.201
#开启系统路由转发功能 vi /etc/sysctl.conf net.ipv4.ip_forward=1 net.ipv4.conf.all.rp_filter=0 net.ipv4.conf.default.rp_filter=0 |
重启防火墙
firewall-cmd --reload
关闭firewall:
systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
屏蔽指定IP访问:
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="120.132.126.133" drop'