2020-09-04-iptables/firewall

[root@web01 ~]# systemctl stop firewalld
[root@web01 ~]# systemctl disable firewalld
[root@web01 ~]# yum -y install iptables iptables-services

[root@web01 ~]# systemctl start iptables
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

[root@web01 ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

[root@web01 ~]# iptables -F
[root@web01 ~]# 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         

[root@web01 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@web01 ~]# iptables-save > /etc/sysconfig/iptables

[root@web01 ~]# 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         
[root@web01 ~]# iptables -t filter -A INPUT -p tcp -j ACCEPT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         


[root@web01 ~]# iptables -I INPUT -p udp -j ACCEPT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         


[root@web01 ~]# iptables -I INPUT 2 -p icmp -j ACCEPT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere            
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination          


[root@web01 ~]# iptables -D INPUT 1
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination          


[root@web01 ~]# iptables -F
[root@web01 ~]# 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         


[root@web01 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@web01 ~]# systemctl restart iptables.service 


[D:\~]$ ping 59.x.x.x

正在 Ping 59.x.x.x 具有 32 字節(jié)的數(shù)據(jù):
來(lái)自 59. 的回復(fù): 字節(jié)=32 時(shí)間=7ms TTL=55
來(lái)自 59. 的回復(fù): 字節(jié)=32 時(shí)間=16ms TTL=55
來(lái)自 59. 的回復(fù): 字節(jié)=32 時(shí)間=7ms TTL=55
來(lái)自 59. 的回復(fù): 字節(jié)=32 時(shí)間=8ms TTL=55

59.x.x.x 的 Ping 統(tǒng)計(jì)信息:
    數(shù)據(jù)包: 已發(fā)送 = 4语稠,已接收 = 4衫哥,丟失 = 0 (0% 丟失),
往返行程的估計(jì)時(shí)間(以毫秒為單位):
    最短 = 7ms疫萤,最長(zhǎng) = 16ms,平均 = 9ms


[root@web01 ~]# iptables -I INPUT -p icmp -j REJECT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     icmp --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

[D:\~]$ ping 59.x.x.x

正在 Ping 59. 具有 32 字節(jié)的數(shù)據(jù):
來(lái)自 59. 的回復(fù): 無(wú)法連到端口。
來(lái)自 59. 的回復(fù): 無(wú)法連到端口。
來(lái)自 59. 的回復(fù): 無(wú)法連到端口队魏。
來(lái)自 59. 的回復(fù): 無(wú)法連到端口。

59.的 Ping 統(tǒng)計(jì)信息:
    數(shù)據(jù)包: 已發(fā)送 = 4弛秋,已接收 = 4器躏,丟失 = 0 (0% 丟失),

[D:\~]$ 


[root@web01 ~]# iptables -I INPUT -s 111.193.X.X -p tcp --dport 22 -j REJECT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     tcp  --  111.193.         anywhere             tcp dpt:ssh reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         


[root@web01 ~]# iptables -I INPUT -s 106.121.x.x -p tcp --dport 22:80 -j REJECT



[root@web01 ~]# iptables -F
[root@web01 ~]# 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         
[root@web01 ~]# iptables -I INPUT -s 106.121.X.X -p tcp --dport 80 -j REJECT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     tcp  --  106.121.X.X       anywhere             tcp dpt:http reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@web01 ~]# iptables -R INPUT 1 -p icmp -s 106.121.X.X -j ACCEPT
[root@web01 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     icmp --  106.121.X.X       anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         


[root@web01 ~]# iptables -F
[root@web01 ~]# systemctl stop iptables
[root@web01 ~]# systemctl start firewalld.service 

[root@web01 ~]# firewall-cmd --get-default-zone 
public

[root@web01 ~]# firewall-cmd --set-default-zone=trusted 
success
[root@web01 ~]# firewall-cmd --reload
success 

[root@web01 ~]# firewall-cmd --set-default-zone=public 
success

[root@web01 ~]# firewall-cmd --permanent --add-service=http --zone=public
success
[root@web01 ~]# firewall-cmd --reload
success

[root@web01 ~]# firewall-cmd --permanent --add-source=106.121.x.x/24 --zone=drop
success
[root@web01 ~]# firewall-cmd --reload
success
[root@web01 ~]# firewall-cmd --permanent --remove-source=106.121.x.x/24 --zone=drop
success
[root@web01 ~]# firewall-cmd --reload
success

[root@web01 ~]# firewall-cmd --permanent --add-port=80/tcp --zone=public 
success
[root@web01 ~]# firewall-cmd --reload
success
[root@web01 ~]# firewall-cmd --permanent --remove-service=http --zone=public 
success
[root@web01 ~]# firewall-cmd --reload
success
[root@web01 ~]# firewall-cmd --permanent --remove-port=80/tcp --zone=public 
success
[root@web01 ~]# firewall-cmd --reload
success
[root@web01 ~]# 

Firewall.jpg
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末蟹略,一起剝皮案震驚了整個(gè)濱河市登失,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌挖炬,老刑警劉巖揽浙,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異意敛,居然都是意外死亡馅巷,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)草姻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)钓猬,“玉大人,你說(shuō)我怎么就攤上這事撩独〕ú埽” “怎么了账月?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)澳迫。 經(jīng)常有香客問(wèn)我局齿,道長(zhǎng),這世上最難降的妖魔是什么橄登? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任抓歼,我火速辦了婚禮,結(jié)果婚禮上拢锹,老公的妹妹穿的比我還像新娘谣妻。我一直安慰自己,他們只是感情好面褐,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布拌禾。 她就那樣靜靜地躺著,像睡著了一般展哭。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上闻蛀,一...
    開(kāi)封第一講書(shū)人閱讀 51,598評(píng)論 1 305
  • 那天匪傍,我揣著相機(jī)與錄音,去河邊找鬼觉痛。 笑死役衡,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的薪棒。 我是一名探鬼主播手蝎,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼俐芯!你這毒婦竟也來(lái)了棵介?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤吧史,失蹤者是張志新(化名)和其女友劉穎邮辽,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體贸营,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡吨述,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了钞脂。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片揣云。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖冰啃,靈堂內(nèi)的尸體忽然破棺而出邓夕,到底是詐尸還是另有隱情肋层,我是刑警寧澤,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布翎迁,位于F島的核電站栋猖,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏汪榔。R本人自食惡果不足惜蒲拉,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望痴腌。 院中可真熱鬧雌团,春花似錦、人聲如沸士聪。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)剥悟。三九已至灵寺,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間区岗,已是汗流浹背略板。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留慈缔,地道東北人叮称。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像藐鹤,于是被迫代替她去往敵國(guó)和親瓤檐。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355