Skip to the content.

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

Môi trường bài lab

Mô hình bài lab

Yêu cầu.

2. Thực hiện bài lab.

2.1. Cấu hình trên PC1.

Th07 09 23:51:03 pc1 systemd[1]: Starting IPv4 firewall with iptables… Th07 09 23:51:03 pc1 iptables.init[1951]: iptables: Applying firewall rules: [ OK ] Th07 09 23:51:03 pc1 systemd[1]: Started IPv4 firewall with iptables. [root@pc1 ~]# iptables -F [root@pc1 ~]# iptables -L 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

- Tạo rule cho phép **PC2** kết nối đến **PC1** qua cổng 22 tcp, và tạo rule chặn tất cả những kết nối khác:
```sh
[root@pc1 ~]# iptables -t filter -A INPUT -p tcp --dport 22 -s 10.11.11.20 -j ACCEPT
[root@pc1 ~]# iptables -t filter -A INPUT -s 10.11.11.20 -j REJECT 
[root@pc1 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  10.11.11.20          anywhere             tcp dpt:ssh
REJECT     all  --  10.11.11.20          anywhere             reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

Th07 10 06:31:33 iptables systemd[1]: Starting IPv4 firewall with iptables… Th07 10 06:31:34 iptables iptables.init[445]: iptables: Applying firewall rules: [ OK ] Th07 10 06:31:34 iptables systemd[1]: Started IPv4 firewall with iptables. [root@iptables ~]# iptables -F [root@iptables ~]# iptables -L 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

- Mặc định, chuyển tiếp IP Ipv4 trên Centos 7 bị tắt, để bật chức năng này, tiến hành chỉnh sửa file **/etc/sysctl.conf**. Thêm dòng sau:

net.ipv4.ip_forward = 1

Sau đó chạy lệnh sau để áp dụng cấu hình:

sysctl -p /etc/sysctl.conf

- Kiểm tra ping từ **Server DC** đến **PC1** thành công và ngược lại:

![](https://i.imgur.com/DvUhVFi.png)

![](https://i.imgur.com/9WPtslU.png)

### 2.3. Cấu hình Nat port
Tiến hành cấu hình Nat port 22 của PC 1 đến Port 22 của Server Iptable:
Cấu hình trên server Iptable:
- Kiểm tra rule trên table *nat*:
```sh
[root@iptables ~]# iptables -t nat -L
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 ~]# 

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 ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] ``` Trên Server DC, ssh đến địa chỉ ip 10.33.33.30 thì có thể kết nối tới PC1

Kết thúc bài lab