ssh
远程链接控制
[root@iptables ~]# which httpd
/usr/sbin/httpd
[root@iptables ~]# vim /etc/hosts.deny
[root@iptables ~]# vim /etc/hosts.allow
1:用211连接 失败
2:用11连接 成功
设置将ssh连接记录记录进/var/log/messages
[root@iptables ~]# vim /etc/hosts.allow
[root@iptables ~]# cat /var/log/messages
Aug 18 22:58:20 mailqq systemd-logind: Removed session 19.
Fri Aug 18 22:58:29 EDT 2017 from 172.25.254.11 to sshd@172.25.254.111
Aug 18 22:58:32 mailqq systemd: Starting Session 20 of user root.
Aug 18 22:58:32 mailqq systemd: Started Session 20 of user root.
Aug 18 22:58:32 mailqq systemd-logind: New session 20 of user root.
将连接记录导入到当前shell
火墙
firewall和iptables最本质的不同是iptables在 /etc/sysconfig/iptables中储存配置,firewall将配置储存在/usr/lib/firewalld/和/etc/firewalld/中的各种XML文件里。
iptables
配置iptables
[root@iptables ~]# yum install iptables-services.x86_64 -y #安装iptables
Loaded plugins: langpacks
Package iptables-services-1.4.21-13.el7.x86_64 already installed and latest version
Nothing to do
[root@iptables ~]# systemctl status iptables.service ##查看iptables状态
iptables.service
Loaded: masked (/dev/null)
Active: inactive (dead)
Warning: Unit file changed on disk, 'systemctl daemon-reload' recommended.
[root@iptables ~]# systemctl status firewalld.service ##查看火墙状态
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
Active: inactive (dead) since Fri 2017-08-18 22:14:54 EDT; 58min ago
Process: 3281 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 3281 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/firewalld.service
Aug 18 21:48:17 mailqq.qq.example.com systemd[1]: Starting firewalld - dynamic ....
Aug 18 21:48:17 mailqq.qq.example.com systemd[1]: Started firewalld - dynamic f....
Aug 18 21:48:18 mailqq.qq.example.com firewalld[3281]: 2017-08-18 21:48:18 ERROR...
Aug 18 22:14:53 mailqq.qq.example.com systemd[1]: Stopping firewalld - dynamic ....
Aug 18 22:14:54 mailqq.qq.example.com systemd[1]: Stopped firewalld - dynamic f....
Hint: Some lines were ellipsized, use -l to show in full.
[root@iptables ~]# systemctl stop firewalld.service #停用firewall
[root@iptables ~]# systemctl disable firewalld.service #开机不启动firewall
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[root@iptables ~]# systemctl mask firewalld.service #冻结firewall
ln -s '/dev/null' '/etc/systemd/system/firewalld.service'
[root@iptables ~]# systemctl start iptables.service #开启iptables
[root@iptables ~]# systemctl status iptables.service
iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled)
Active: active (exited) since Fri 2017-08-18 23:18:37 EDT; 9s ago
Process: 5748 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 5748 (code=exited, status=0/SUCCESS)
Aug 18 23:18:37 iptables.example.com iptables.init[5748]: iptables: Applying fir...
Aug 18 23:18:37 iptables.example.com systemd[1]: Started IPv4 firewall with ipt....
Hint: Some lines were ellipsized, use -l to show in full.
[root@iptables ~]# systemctl enable iptables.service ##设置开机启动
ln -s '/usr/lib/systemd/system/iptables.service' '/etc/systemd/system/basic.target.wants/iptables.srvice'
1:input
2:output
3:forwarder
4:postouting SNAT 地址转换路由后
5:prorouting DNAT 地址转换路由前(回来)
三张表,五条链
filter (input output forwder ) 经过内核
nat (input output postouting prorouting) 经过本机
mangle 附加表
1 iptables -t filter -nL ##查看
2 iptables -F ##刷新
未保存,刷新后恢复到最初的样子
3 service iptables save ##保存
[root@iptables ~]# iptables -t filter -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# iptables -t nat -nL
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# iptables -t mangle -nL
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.21 on Thu Aug 17 05:07:20 2017
*filter
:INPUT ACCEPT [136:10844]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [78:7180]
COMMIT
# Completed on Thu Aug 17 05:07:20 2017
对所有输入直接拒绝,输入下面命令,ssh不能用,此时进入虚拟机主机,输入如图命令,等待几分钟,恢复如初。
[root@iptables ~]# iptables -P INPUT DROP
[root@iptables ~]# iptables -A INPUT -j REJECT ##对所有服务关闭
iptables -P INPUT ACCEPUT|DROP ##
iptables -I INPUT 1 -i lo -j ACCEPT ##插入
iptables -I INPUT 2 -s 172.25.254.x -p tcp –dport 22 -j ACCEPT ##插入
iptables -I INPUT 3 -P TCP –drop 80 -j ACCEPT
iptables -D input 3 ##删除
cat /etc/sysconfig/iptables
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT all -- 172.25.254.11 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# iptables -D INPUT 2 ##删除
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT all -- 172.25.254.11 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
添加WESTOS这一项,修改WESTOS为redhat,删除redhat
[root@iptables ~]# iptables -N WESTOS
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT all -- 172.25.254.11 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain WESTOS (0 references)
target prot opt source destination
[root@iptables ~]# iptables -E WESTOS redhat
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT all -- 172.25.254.11 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain redhat (0 references)
target prot opt source destination
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 172.25.254.11 0.0.0.0/0 tcp dpt:22
ACCEPT all -- 172.25.254.11 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
接口的开启与查看
[root@iptables ~]# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 20 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 139 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p tcp --dport 445 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p udp --dport 445 -j ACCEPT
[root@iptables ~]# iptables -A INPUT -m state --state NEW -p udp --dport 139 -j ACCEPT
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:20
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:21
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:139
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:445
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:445
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:139
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@iptables ~]# cat /etc/services | grep dns
dnsix 90/tcp # DNSIX Securit Attribute Token Map
dnsix 90/udp # DNSIX Securit Attribute Token Map
sdnskmp 558/tcp # SDNSKMP
sdnskmp 558/udp # SDNSKMP
dns2go 1227/tcp # DNS2Go
dns2go 1227/udp # DNS2Go
menandmice-dns 1337/tcp # menandmice DNS
menandmice-dns 1337/udp # menandmice DNS
sunscalar-dns 1870/tcp # SunSCALAR DNS Service
sunscalar-dns 1870/udp # SunSCALAR DNS Service
ddns-v3 2164/tcp # Dynamic DNS Version 3
ddns-v3 2164/udp # Dynamic DNS Version 3
spw-dnspreload 3849/tcp # SPACEWAY DNS Preload
spw-dnspreload 3849/udp # SPACEWAY DNS Prelaod
dns-llq 5352/tcp # DNS Long-Lived Queries
dns-llq 5352/udp # DNS Long-Lived Queries
mdns 5353/tcp # Multicast DNS
mdns 5353/udp # Multicast DNS
mdnsresponder 5354/tcp noclog # Multicast DNS Responder IPC
mdnsresponder 5354/udp noclog # Multicast DNS Responder IPC
ub-dns-control 8953/tcp # unbound dns nameserver control
odnsp 9966/tcp # OKI Data Network Setting Protocol
odnsp 9966/udp # OKI Data Network Setting Protocol
[root@iptables ~]# cat /etc/services | grep name
# service-name port/protocol [aliases ...] [# comment]
nameserver 42/tcp name # IEN 116
nameserver 42/udp name # IEN 116
nicname 43/tcp whois
nicname 43/udp whois
domain 53/tcp # name-domain server
hostname 101/tcp hostnames # usually from sri-nic
hostname 101/udp hostnames # usually from sri-nic
csnet-ns 105/tcp cso # also used by CSO name server
at-nbp 202/tcp # AppleTalk name binding
#>Ports are used in the TCP [RFC793] to name the ends of logical
# Gracilis Packeten remote config server. The official name is listed as
# the primary name, with the unregistered name as an alias.
# being registred. The primary names are the registered names, and the
# unregistered names used by zebra are listed as aliases.
# This port is registered as wnn6, but also used under the unregistered name
swat 901/tcp smpnameres # Samba Web Administration Tool
ptcnameservice 597/tcp # PTC Name Service
ptcnameservice 597/udp # PTC Name Service
smpnameres 901/udp # SMPNAMERES
oraclenames 1575/tcp # oraclenames
oraclenames 1575/udp # oraclenames
enl-name 1805/tcp # ENL-Name
enl-name 1805/udp # ENL-Name
linkname 1903/tcp # Local Link Name Resolution
linkname 1903/udp # Local Link Name Resolution
bcinameservice 3415/tcp # BCI Name Service
bcinameservice 3415/udp # BCI Name Service
namemunge 3950/tcp # Name Munging
namemunge 3950/udp # Name Munging
fmpro-internal 5003/udp # FileMaker, Inc. - Proprietary name binding
ub-dns-control 8953/tcp # unbound dns nameserver control
[root@iptables ~]# cat /etc/services | grep bind
sunrpc 111/tcp portmapper rpcbind # RPC 4.0 portmapper TCP
sunrpc 111/udp portmapper rpcbind # RPC 4.0 portmapper UDP
at-nbp 202/tcp # AppleTalk name binding
ocbinder 183/tcp # OCBinder
ocbinder 183/udp # OCBinder
unbind-cluster 2138/tcp # UNBIND-CLUSTER
unbind-cluster 2138/udp # UNBIND-CLUSTER
binderysupport 2302/tcp # Bindery Support
binderysupport 2302/udp # Bindery Support
magbind 3194/tcp # Rockstorm MAG protocol
magbind 3194/udp # Rockstorm MAG protocol
fmpro-internal 5003/udp # FileMaker, Inc. - Proprietary name binding
[root@iptables ~]# cat /etc/services | grep domain
domain 53/tcp # name-domain server
domain 53/udp
domaintime 9909/tcp # domaintime
domaintime 9909/udp # domaintime
[root@iptables ~]# cat /etc/services | grep nfs
nfs 2049/tcp nfsd shilp # Network File System
nfs 2049/udp nfsd shilp # Network File System
nfs 2049/sctp nfsd shilp # Network File System
netconfsoaphttp 832/tcp # NETCONF for SOAP over HTTPS
netconfsoaphttp 832/udp # NETCONF for SOAP over HTTPS
netconfsoapbeep 833/tcp # NETCONF for SOAP over BEEP
netconfsoapbeep 833/udp # NETCONF for SOAP over BEEP
nfsd-keepalive 1110/udp # Client status info
picknfs 1598/tcp # picknfs
picknfs 1598/udp # picknfs
shiva_confsrvr 1651/tcp shiva-confsrvr # shiva_confsrvr
shiva_confsrvr 1651/udp shiva-confsrvr # shiva_confsrvr
3d-nfsd 2323/tcp # 3d-nfsd
3d-nfsd 2323/udp # 3d-nfsd
mediacntrlnfsd 2363/tcp # Media Central NFSD
mediacntrlnfsd 2363/udp # Media Central NFSD
winfs 5009/tcp # Microsoft Windows Filesystem
winfs 5009/udp # Microsoft Windows Filesystem
enfs 5233/tcp # Etinnae Network File Service
nfsrdma 20049/tcp # Network File System (NFS) over RDMA
nfsrdma 20049/udp # Network File System (NFS) over RDMA
nfsrdma 20049/sctp # Network File System (NFS) over RDMA
[root@iptables ~]# cat /etc/services | grep squid
squid 3128/tcp ndl-aas # squid web proxy
接口设定
[root@iptables ~]# lftp 172.25.254.111
lftp 172.25.254.111:~> ls
Interrupt
lftp 172.25.254.111:~> quit
[root@iptables ~]# vim /etc/vsftpd/vsftpd.conf
[root@iptables ~]# systemctl restart vsftpd
[root@iptables ~]# iptables -I INPUT 2 -m state --state NEW
[root@iptables ~]# iptables -I INPUT 2 -m state --state NEW -p tcp --dport 7000 -j ACCEPT
[root@iptables ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:7000
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:20
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:21
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:139
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:445
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:445
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:139
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@iptables ~]# lftp 172.25.254.111lftp 172.25.254.111:~> ls
Interrupt
lftp 172.25.254.111:/> quit
[root@iptables ~]# vim /etc/vsftpd/vsftpd.conf [root@iptables ~]# systemctl restart iptables.service
[root@iptables ~]# lftp 172.25.254.111
lftp 172.25.254.111:~> ls
Interrupt
lftp 172.25.254.111:/> quit
[root@iptables ~]# getenforce
Enforcing
[root@iptables ~]# setenforce 0
[root@iptables ~]# lftp 172.25.254.111
lftp 172.25.254.111:~> ls
drwxr-xr-x 2 0 0 6 Mar 07 2014 pub
地址伪装
[root@iptables ~]# iptables -F #刷掉以前策略
[root@iptables ~]# service iptables save #保存
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@iptables ~]# iptables -t nat -nL #查看
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
[root@iptables ~]# ip addr show #创建双网卡
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:00:0b:0b brd ff:ff:ff:ff:ff:ff
inet 172.25.254.111/24 brd 172.25.254.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe00:b0b/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:11:b3:12 brd ff:ff:ff:ff:ff:ff
inet 172.25.11.111/24 brd 172.25.11.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe11:b312/64 scope link
valid_lft forever preferred_lft forever
[root@iptables ~]# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 172.25.254.111
[root@iptables ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@iptables ~]# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-dest 172.25.11.211
测试
不在同一网段,连接成功
firewall
停用iptables,召唤回firewall
[root@firewall ~]# firewall-cmd --list-all #查看firewall为public
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp ssh #开启的服务
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@firewall ~]# firewall-cmd --get-zones
ROL block dmz drop external home internal public trusted work
域的查看和改变
[root@firewall ~]# firewall-cmd --get-zones
ROL block dmz drop external home internal public trusted work
[root@firewall ~]# firewall-cmd --get-default-zone
public
[root@firewall ~]# firewall-cmd --set-default-zone=trusted
success
[root@firewall ~]# firewall-cmd --get-default-zone
trusted
添加服务
[root@firewall ~]# firewall-cmd --add-service=
amanda-client kpasswd pop3s
bacula ldap postgresql
bacula-client ldaps proxy-dhcp
dhcp libvirt radius
dhcpv6 libvirt-tls rpc-bind
dhcpv6-client mdns samba
dns mountd samba-client
ftp ms-wbt smtp
high-availability mysql ssh
http nfs telnet
https ntp tftp
imaps openvpn tftp-client
ipp pmcd transmission-client
ipp-client pmproxy vnc-server
ipsec pmwebapi wbem-https
kerberos pmwebapis
[root@firewall ~]# firewall-cmd --add-service=http
success
[root@firewall ~]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
修改文件
[root@firewall ~]# cd /etc/firewalld/zones/
[root@firewall zones]# ls
public.xml public.xml.old ROL.xml trusted.xml trusted.xml.old
[root@firewall zones]# vim public.xml
临时xml文件,删除之后服务不能运行,但是重新启动firewall文件又回来了
[root@firewall zones]# cd /usr/lib/firewalld/services/
[root@firewall services]# ls
amanda-client.xml ipp-client.xml mysql.xml rpc-bind.xml
bacula-client.xml ipp.xml nfs.xml samba-client.xml
bacula.xml ipsec.xml ntp.xml samba.xml
dhcpv6-client.xml kerberos.xml openvpn.xml smtp.xml
dhcpv6.xml kpasswd.xml pmcd.xml ssh.xml
dhcp.xml ldaps.xml pmproxy.xml telnet.xml
dns.xml ldap.xml pmwebapis.xml tftp-client.xml
ftp.xml libvirt-tls.xml pmwebapi.xml tftp.xml
high-availability.xml libvirt.xml pop3s.xml transmission-client.xml
https.xml mdns.xml postgresql.xml vnc-server.xml
http.xml mountd.xml proxy-dhcp.xml wbem-https.xml
imaps.xml ms-wbt.xml radius.xml
查看服务接口
[root@firewall services]# lsmod | grep nf
nf_conntrack_ftp 18638 0
nf_conntrack_ipv6 18738 8
nf_defrag_ipv6 34651 1 nf_conntrack_ipv6
nf_nat_ipv6 13279 1 ip6table_nat
nf_conntrack_ipv4 14862 7
nf_defrag_ipv4 12729 1 nf_conntrack_ipv4
nf_nat_ipv4 13263 1 iptable_nat
nf_nat 21798 4 nf_nat_ipv4,nf_nat_ipv6,ip6table_nat,iptable_nat
nf_conntrack 101024 9 nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,ip6table_nat,nf_conntrack_ftp,iptable_nat,nf_conntrack_ipv4,nf_conntrack_ipv6
binfmt_misc 17468 1
nfsd 284378 1
auth_rpcgss 59368 1 nfsd
nfs_acl 12837 1 nfsd
lockd 93977 1 nfsd
sun[root@firewall services]# modprobe -r nf_conntrack_ftp #端口的删除
[root@firewall services]# lsmod | grep nf
nf_conntrack_ipv6 18738 8
nf_defrag_ipv6 34651 1 nf_conntrack_ipv6
nf_nat_ipv6 13279 1 ip6table_nat
nf_conntrack_ipv4 14862 7
nf_defrag_ipv4 12729 1 nf_conntrack_ipv4
nf_nat_ipv4 13263 1 iptable_nat
nf_nat 21798 4 nf_nat_ipv4,nf_nat_ipv6,ip6table_nat,iptable_nat
nf_conntrack 101024 8 nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,ip6table_nat,iptable_nat,nf_conntrack_ipv4,nf_conntrack_ipv6
binfmt_misc 17468 1
nfsd 284378 1
auth_rpcgss 59368 1 nfsd
nfs_acl 12837 1 nfsd
lockd 93977 1 nfsd
sunrpc 293453 5 nfsd,auth_rpcgss,lockd,nfs_acl
rpc 293453 5 nfsd,auth_rpcgss,lockd,nfs_acl
[root@firewall services]# systemctl restart firewalld.service
[root@firewall services]# lsmod | grep nf
nf_conntrack_ftp 18638 0
nf_conntrack_ipv6 18738 8
nf_defrag_ipv6 34651 1 nf_conntrack_ipv6
nf_nat_ipv6 13279 1 ip6table_nat
nf_conntrack_ipv4 14862 7
nf_defrag_ipv4 12729 1 nf_conntrack_ipv4
nf_nat_ipv4 13263 1 iptable_nat
nf_nat 21798 4 nf_nat_ipv4,nf_nat_ipv6,ip6table_nat,iptable_nat
nf_conntrack 101024 9 nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,ip6table_nat,nf_conntrack_ftp,iptable_nat,nf_conntrack_ipv4,nf_conntrack_ipv6
binfmt_misc 17468 1
nfsd 284378 1
auth_rpcgss 59368 1 nfsd
nfs_acl 12837 1 nfsd
lockd 93977 1 nfsd
sunrpc 293453 5 nfsd,auth_rpcgss,lockd,nfs_acl
指定端口的打开
[root@firewall services]# firewall-cmd --permanent --add-port=8080/tcp
success
[root@firewall services]# firewall-cmd --reload
success
[root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp ssh
ports: 8080/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@firewall services]# vim /etc/httpd/conf/httpd.conf
[root@firewall services]# systemctl restart httpd.service
[root@firewall services]# firewall-cmd --permanent --remove-service=http
success
[root@firewall services]# firewall-cmd --permanent --remove-port=8080/tcp
success
[root@firewall services]# firewall-cmd --reload
success
添加特定用户
[root@firewall services]# firewall-cmd --permanent --add-source=172.25.254.11 --zone=trusted
success
[root@firewall services]# firewall-cmd --reload
success
添加某个网段为信任网段
[root@firewall services]# firewall-cmd --permanent --add-source=172.25.254.0/24 --zone=trusted
success
[root@firewall services]# firewall-cmd --reload
success
网卡的移动
[root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0 eth1
sources:
services: dhcpv6-client ftp ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@firewall services]# firewall-cmd --permanent --remove-interface=eth1 --zone=public
success
[root@firewall services]# firewall-cmd --permanent --add-interface=eth1 --zone=trusted
success
[root@firewall services]# systemctl restart firewalld.service [root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
direct rules
[root@firewall services]# firewall-cmd --direct --get-all-rules ipv4 filter INPUT 1 -s 172.25.254.0/24 -p tcp --dport 80 -j REJECT
[root@firewall services]# firewall-cmd --reload
success
[root@firewall services]# firewall-cmd --direct --get-all-rules
ipv4 filter INPUT 1 -s 172.25.254.0/24 -p tcp --dport 80 -j REJECT
伪装
开启伪装功能
[root@firewall services]# firewall-cmd --permanent --add-masquerade
success
[root@firewall services]# firewall-cmd --reload
success
[root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp
ports:
masquerade: yes
forward-ports:
icmp-blocks:
rich rules:
[root@firewall services]# firewall-cmd --permanent --zone=public --add-forward-port=port=22:proto=tcp:toport=22:toaddr=172.25.11.211
success
[root@firewall services]# firewall-cmd --reload
success
[root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp
ports:
masquerade: yes
forward-ports: port=22:proto=tcp:toport=22:toaddr=172.25.11.211
icmp-blocks:
rich rules:
[root@firewall services]# firewall-cmd --add-rich-rule='rule family=ipv4 source address=172.25.254.111 masquerade'
success
[root@firewall services]# firewall-cmd --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client ftp http
ports:
masquerade: yes
forward-ports: port=22:proto=tcp:toport=22:toaddr=172.25.11.211
icmp-blocks:
rich rules:
rule family="ipv4" source address="172.25.254.111" masquerade
[root@firewall services]# firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=172.25.254.11 forward-port port=22 protocol=tcp to-port=22 to-addr=172.25.11.211"
success
[root@firewall services]# geten
getenforce getent
[root@firewall services]# getenforce
Permissive
[root@firewall services]# setenforce 0