Open Source How-To

You are here: Home > 3. Ubuntu 16.04 Server > ติดตั้ง shorewall (two interfaces) บน ubuntu 16.04 server

ติดตั้ง shorewall (two interfaces) บน ubuntu 16.04 server

 
 

บันทึกนี้ปรับปรุงล่าสุดเมื่อวันที่ 15-08-2559
ดูแลโดย WIBOON

  • ตัวอย่างการนำไปใช้งาน เช่น ใช้ทำ NAT router เป็นต้น
  • ตรวจสอบด้วย ifconfig ก่อนว่า ได้ network interface ชื่อ eth0 หรือ อย่างอื่น หากได้เป็นอย่างอื่น เช่น enp0s3 เป็นต้น เมื่อจะ config shorewall ให้แก้ไขจาก eth0 เป็น enp0s3 ในไฟล์ /etc/shorewall/interfaces ด้วย

 

ขั้นตอน
1.ติดตั้ง package
sudo apt-get install shorewall

2.คัดลอกตัวอย่างมาใช้เป็นค่าเริ่มต้น
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/zones /etc/shorewall
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/interfaces /etc/shorewall
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/policy /etc/shorewall
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/rules /etc/shorewall
sudo cp /usr/share/doc/shorewall/examples/two-interfaces/masq /etc/shorewall

3.ตรวจสอบค่าต่าง ๆ สำหรับไฟล์เหล่านี้คือ zones, interfaces, policy และ masq ซึ่งยังไม่ได้แก้ไข
ไฟล์ /etc/shorewall/zones

#ZONE   TYPE    OPTIONS                 IN                      OUT
#                                       OPTIONS                 OPTIONS
fw      firewall
net     ipv4
loc     ipv4

ไฟล์ /etc/shorewall/interfaces

###############################################################################
?FORMAT 2
###############################################################################
#ZONE   INTERFACE       OPTIONS
net     eth0            dhcp,tcpflags,nosmurfs,routefilter,logmartians,sourceroute=0
loc     eth1            tcpflags,nosmurfs,routefilter,logmartians

ไฟล์ /etc/shorewall/policy

#SOURCE         DEST            POLICY          LOG LEVEL       LIMIT:BURST
$FW net ACCEPT
$FW loc ACCEPT
loc             net             ACCEPT
loc $FW ACCEPT
net             all             DROP            info
# THE FOLLOWING POLICY MUST BE LAST
all all ACCEPT

ไฟล์ /etc/shorewall/masq

#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL # GROUP DEST eth0 10.0.0.0/8,\ 169.254.0.0/16,\ 172.16.0.0/12,\ 192.168.0.0/16 

4.แก้ไขไฟล์ rules
sudo vi /etc/shorewall/rules

ที่บรรทัดนี้ ประมาณบรรทัดที่ 43 หมายถึง ไม่อนุญาตให้ ping มาที่เครื่อง server

Ping(DROP)     net             $FW

เพิ่ม เพื่อให้ ping เครื่อง firewall นี้ได้จากเครื่องใด ๆ ใน net ตัวอย่างเช่น 192.168.1.0/24

ACCEPT net:192.168.1.0/24 $FW icmp
Ping(DROP)     net             $FW

เพิ่มให้ ping ได้จากเครื่อง firewall นี้

ACCEPT $FW loc icmp
ACCEPT $FW net icmp

เพิ่มรายการตัวอย่างเหล่านี้

# example drop unwanted intranet net
#DROP loc:10.0.100.193 $FW
# example drop unwanted internet net
#DROP net:42.2.192.0/19 $FW
# default open all ports
ACCEPT all $FW
# or open only SSH
#ACCEPT all $FW tcp 22
# or open only DHCPD
#ACCEPT all $FW udp 67:68
# or open only HTTP,HTTPS
#ACCEPT all $FW tcp 80,443

 

5.ตั้งค่า เปิดใช้งาน shorewall
แก้ไขไฟล์ /etc/default/shorewall
ให้ใช้ค่านี้
startup=1

แก้ไขไฟล์ /etc/shorewall/shorewall.conf
ให้ใช้ค่านี้
STARTUP_ENABLED=Yes
IP_FORWARDING=Yes

6.เปิดใช้งาน
sudo systemctl start shorewall.service

7.ตรวจสอบสถานะ
sudo systemctl status shorewall.service

ผลลัพธ์ อย่างนี้พร้อมใช้งาน

- shorewall.service - Shorewall IPv4 firewall
   Loaded: loaded (/lib/systemd/system/shorewall.service; disabled; vendor prese
   Active: active (exited) since Wed 2016-08-10 10:58:26 ICT; 3s ago
  Process: 2338 ExecStart=/sbin/shorewall $OPTIONS start $STARTOPTIONS (code=exi
 Main PID: 2338 (code=exited, status=0/SUCCESS)

ผลลัพธ์ อย่างนี้ไม่พร้อมใช้งาน

[sudo] password for mama:
- shorewall.service - Shorewall IPv4 firewall
   Loaded: loaded (/lib/systemd/system/shorewall.service; disabled; vendor prese
   Active: inactive (dead)

 

8.ตั้งค่าให้ shorewall สตาร์ทด้วยเมื่อ reboot เครื่อง server
sudo systemctl enable shorewall.service

nach oben