阿里雲Ubuntu16配置iptables防火牆

2022-04-04 12:11:00 字數 1802 閱讀 9858

# whereis iptables #檢視系統是否安裝防火牆可以看到:

iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已經安裝iptables

apt-get install 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

# vi /etc/iptables.rules

新增以下內容(備註:80是指web伺服器端口,3306是指mysql資料庫鏈結埠,22是指ssh遠端管理埠.)

*filter

:input drop [0:0]

:forward accept [0:0]

:output accept [0:0]

:syn-flood - [0:0]

-a input -i lo -j accept

-a input -m state --state related,established -j accept

-a input -p tcp -m state --state new -m tcp --dport 22 -j accept

-a input -p tcp -m state --state new -m tcp --dport 80 -j accept

-a input -p tcp -m state --state new -m tcp --dport 443 -j accept

-a input -p tcp -m state --state new -m tcp --dport 3306 -j accept

-a input -p icmp -m limit --limit 100/sec --limit-burst 100 -j accept

-a input -p icmp -m limit --limit 1/s --limit-burst 10 -j accept

-a input -p tcp -m tcp --tcp-flags fin,syn,rst,ack syn -j syn-flood

-a input -j reject --reject-with icmp-host-prohibited

-a syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j return

-a syn-flood -j reject --reject-with icml-port-unreachable

commit

# iptables-restore < /etc/iptables.rules #使防火牆規則生效

# vi /etc/network/if-pre-up.d/iptables #建立檔案,新增以下內容,使防火牆開機啟動

#!/bin/bash

iptables-restore < /etc/iptables.rules

# chmod +x /etc/network/if-pre-up.d/iptables #新增執行許可權

# iptables -l -n檢視規則是否生效.

阿里雲ubuntu配置

在使用阿里雲esc伺服器時遇到了一些問題,在此把整個過程從頭到尾敘述一遍,以供參考。1.初始系統無圖形化桌面 2.圖形介面只有guest 3.初始賬戶為root,不適用於普通使用,新增新賬戶 4.ssh及xrdp配置 5.其他配置 bin bash 更新軟體庫 apt get update 安裝ub...

Ubuntu16 設計主機名和靜態ip

設定主機名 sudo vi etc hostname 輸入主機名後儲存退出開啟配置檔案 sudo vi etc network inte ces 設定靜態ip後退出 auto ens33 iface ens33 inet dhcp 注釋掉原來的dhcp自動獲取ip,新增下列靜態配置 iface en...

ubuntu16安裝後的常用配置 一

docker ubuntu預設情況下沒有啟用root使用者,安裝系統時建立的使用者使用sudo可以擁有root的許可權。但為了方便,最好啟用root使用者 sudo passwd root 先備份 sudo cp etc apt sources.list etc apt sources.list b...