CentOS 7 trae un nuevo servicio llamado FirewallD que es el reemplazo de la ya conococida “iptables”. Si la máquina va a ser usada como servidor es importante que tenga un cortafuego (firewall) para bloquear algunos servicios.
1. Activar/Habilitar el firewall
Para activar y habilitar el firewall digite el siguiente comando:
1
2
|
[root@localhost~]# systemctl start firewalld
[root@localhost~]# systemctl enable firewalld
|
2. Zonas
Para saber que zonas por defecto están habilitadas:
1
2
|
[root@localhost~]# firewall-cmd --get-default-zone
public
|
Por defecto esta zona es “public” y se aplica sobre la tarjeta de red (enp0s3).
1
2
3
4
5
6
7
8
9
10
|
[root@localhost~]# firewall-cmd --list-all
public(default)
interfaces:enp0s3
sources:
services:dhcpv6-client ssh
ports:
masquerade:no
forward-ports:
icmp-blocks:
rich rules:
|
Los servicios activos son el dhcpv6-client y el ssh, este último por defecto usa la puerta 22.
Para ver todas las zonas, digite el siguiente comando:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@localhost~]# firewall-cmd --list-all-zones
block
interfaces:
sources:
services:
ports:
masquerade:no
forward-ports:
icmp-blocks:
rich rules:
dmz
interfaces:
sources:
services:ssh
...
|
Para listar una zona específica, por ejemplo “external”, digite el siguiente comando:
1
2
|
[root@localhost~]# firewall-cmd --list-service --zone=external
ssh
|
Si queremos cambiar la zona, por ejemplo de “public” hacia “external”, digite el siguiente comando:
1
2
|
[root@localhost~]# firewall-cmd --set-default-zone=external
success
|
3. Servicios
El firewall puede filtrar varios servicios, por ejemplo ssh (puerta 22), http (80), mysql (3306) entre otros. Para listar los servicios definidos por defecto:
1
2
|
[root@localhost~]# firewall-cmd --get-services
RH-Satellite-6amanda-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
|
Para poder adicionar mas servicios, se puede adicionar un nuevo archivo xml en la siguiente dirección: /usr/lib/firewalld/services
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@localhost~]# ls /usr/lib/firewalld/services
amanda-client.xml ipp-client.xml mysql.xml RH-Satellite-6.xml
bacula-client.xml ipp.xml nfs.xml rpc-bind.xml
bacula.xml ipsec.xml ntp.xml samba-client.xml
dhcpv6-client.xml kerberos.xml openvpn.xml samba.xml
dhcpv6.xml kpasswd.xml pmcd.xml smtp.xml
dhcp.xml ldaps.xml pmproxy.xml ssh.xml
dns.xml ldap.xml pmwebapis.xml telnet.xml
ftp.xml libvirt-tls.xml pmwebapi.xml tftp-client.xml
high-availability.xml libvirt.xml pop3s.xml tftp.xml
https.xml mdns.xml postgresql.xml transmission-client.xml
http.xml mountd.xml proxy-dhcp.xml vnc-server.xml
imaps.xml ms-wbt.xml radius.xml wbem-https.xml
|
Para adicionar o remover los servicios a nuestra zona (por ejemplo el servicio http):
1
2
3
4
5
6
7
8
|
[root@localhost~]# firewall-cmd --add-service=http
success
[root@localhost~]# firewall-cmd --list-service
http ssh
[root@localhost~]# firewall-cmd --remove-service=http
success
[root@localhost~]# firewall-cmd --list-service
ssh
|
Si reiniciamos la máquina, el servicio que adicionamos desaparece. Por tanto para que quede permanente solo necesitamos adicionar a nuestro comando la palabra “–permanent” y lo siguiente es hacer un reload del servicio.
1
2
3
4
5
6
|
[root@localhost~]# firewall-cmd --add-service=http --permanent
success
[root@localhost~]# firewall-cmd --reload
success
[root@localhost~]# firewall-cmd --list-service
http ssh
|
4. Puertas
Si queremos adicionar o remover una puerta (por ejemplo TCP 465), lo podemos hacer de la siguiente manera:
1
2
3
4
5
6
7
|
[root@localhost~]# firewall-cmd --add-port=465/tcp
success
[root@localhost~]# firewall-cmd --list-port
465/tcp
[root@localhost~]# firewall-cmd --remove-port=465/tcp
success
[root@localhost~]# firewall-cmd --list-port
|
Si queremos hacerla permanente:
1
2
3
4
5
6
|
[root@localhost~]# firewall-cmd --add-port=465/tcp --permanent
success
[root@localhost~]# firewall-cmd --reload
success
[root@localhost~]# firewall-cmd --list-port
465/tcp
|
5. ICMP Types
De igual manera para para adicionar o remover “ICMP Types”:
1
2
3
4
5
6
7
8
9
|
[root@localhost~]# firewall-cmd --add-icmp-block=echo-request
success
[root@localhost~]# firewall-cmd --list-icmp-blocks
echo-request
[root@localhost~]# firewall-cmd --remove-icmp-block=echo-request
success
[root@localhost~]# firewall-cmd --list-icmp-blocks
[root@localhost~]# firewall-cmd --get-icmptypes
destination-unreachable echo-reply echo-request parameter-problem redirect router-advertisement router-solicitation source-quench time-exceeded
|