Skip to the content.

Thực hành cấu hình firewalld

1. Yêu cầu bài lab

Mô hình bài lab.

Yêu cầu bài lab

2. Cấu hình bài lab.

2.1. Cấu hình cho PC1 và PC2 truy cập được internet.

Ta thấy cả ba card mạng của server đang ở zone public, tiến hành đổi Interface:

Kiểm tra ping từ pc1 đến pc2:

[root@firewalld ~]# firewall-cmd --list-all --zone external 
external (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens35
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 	

Nếu tính năng masquerade, chưa được bật, chạy lệnh:

# firewall-cmd --zone external --add-masquerade

Kiểm tra truy cập internet trên PC1 và PC2:

2.2. Cấu hình chặn truy cập giữa PC1 và PC2, chặn PC1 truy cập baomoi.vn .

#### Chặn PC1 truy cập baomoi.vn:
- Kiểm tra địa chỉ ip của website `baomoi.vn`:

[root@firewalld ~]# nslookup

baomoi.vn Server: 8.8.8.8 Address: 8.8.8.8#53

Non-authoritative answer: Name: baomoi.vn Address: 118.102.1.120

- Kiểm tra kết nối đến port 80 và 443 của webserver baomoi.vn bằng `telnet` có thể thấy PC1 vẫn đang kết nối được đến web của baomoi.vn:

[root@pc1 ~]# telnet baomoi.vn 80 Trying 118.102.1.120… Connected to baomoi.vn. Escape character is ‘^]’.

[root@pc1 ~]# telnet baomoi.vn 443 Trying 118.102.1.120… Connected to baomoi.vn. Escape character is ‘^]’.

- Tạo Direct rule chặn các truy cập từ PC1 đến trang web:
```sh
[root@firewalld ~]# firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -d 10.11.11.10 -s  118.102.1.120 -j REJECT
success

2.3. Cấu hình port forwarding