国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

Linux|Centos|Ubuntu|系統(tǒng)進(jìn)程|Fedora|注冊(cè)表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服務(wù)器之家 - 服務(wù)器系統(tǒng) - Linux - 詳解Linux防火墻iptables禁IP與解封IP常用命令

詳解Linux防火墻iptables禁IP與解封IP常用命令

2022-03-02 16:56欲思 Linux

這篇文章主要介紹了詳解Linux防火墻iptables禁IP與解封IP常用命令,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

在Linux服務(wù)器被攻擊的時(shí)候,有的時(shí)候會(huì)有幾個(gè)主力IP。如果能拒絕掉這幾個(gè)IP的攻擊的話,會(huì)大大減輕服務(wù)器的壓力,說(shuō)不定服務(wù)器就能恢復(fù)正常了。

在Linux下封停IP,有封殺網(wǎng)段和封殺單個(gè)IP兩種形式。一般來(lái)說(shuō),現(xiàn)在的攻擊者不會(huì)使用一個(gè)網(wǎng)段的IP來(lái)攻擊(太招搖了),IP一般都是散列的。于是下面就詳細(xì)說(shuō)明一下封殺單個(gè)IP的命令,和解封單個(gè)IP的命令。

Linux防火墻:iptables禁IP與解封IP常用命令

在Linux下,使用ipteables來(lái)維護(hù)IP規(guī)則表。要封停或者是解封IP,其實(shí)就是在IP規(guī)則表中對(duì)入站部分的規(guī)則進(jìn)行添加操作。

要封停一個(gè)IP,使用下面這條命令:

?
1
iptables -I INPUT -s ***.***.***.*** -j DROP

要解封一個(gè)IP,使用下面這條命令:

?
1
iptables -D INPUT -s ***.***.***.*** -j DROP

參數(shù)-I是表示Insert(添加),-D表示Delete(刪除)。后面跟的是規(guī)則,INPUT表示入站,***.***.***.***表示要封停的IP,DROP表示放棄連接。

此外,還可以使用下面的命令來(lái)查看當(dāng)前的IP規(guī)則表:

?
1
iptables -list

比如現(xiàn)在要將123.44.55.66這個(gè)IP封殺,就輸入:

?
1
iptables -I INPUT -s 123.44.55.66 -j DROP

要解封則將-I換成-D即可,前提是iptables已經(jīng)有這條記錄。如果要想清空封掉的IP地址,可以輸入:

?
1
iptables -flush

要添加IP段到封停列表中,使用下面的命令:

?
1
iptables -I INPUT -s 121.0.0.0/8 -j DROP

其實(shí)也就是將單個(gè)IP封停的IP部分換成了Linux的IP段表達(dá)式。關(guān)于IP段表達(dá)式網(wǎng)上有很多詳細(xì)解說(shuō)的,這里就不提了。

相信有了iptables的幫助,解決小的DDoS之類的攻擊也不在話下!

附:其他常用的命令

編輯 iptables 文件

?
1
vi /etc/sysconfig/iptables

關(guān)閉/開啟/重啟防火墻

?
1
2
3
/etc/init.d/iptables stop
#start 開啟
#restart 重啟

驗(yàn)證一下是否規(guī)則都已經(jīng)生效:

?
1
iptables -L

保存并重啟iptables

?
1
2
/etc/rc.d/init.d/iptables save
service iptables restart

linux下實(shí)用iptables封ip段的一些常見命令:

封單個(gè)IP的命令是:

?
1
iptables -I INPUT -s 211.1.0.0 -j DROP

封IP段的命令是:

?
1
2
3
iptables -I INPUT -s 211.1.0.0/16 -j DROP
iptables -I INPUT -s 211.2.0.0/16 -j DROP
iptables -I INPUT -s 211.3.0.0/16 -j DROP

封整個(gè)段的命令是:

?
1
iptables -I INPUT -s 211.0.0.0/8 -j DROP

封幾個(gè)段的命令是:

?
1
2
iptables -I INPUT -s 61.37.80.0/24 -j DROP
iptables -I INPUT -s 61.37.81.0/24 -j DROP

想在服務(wù)器啟動(dòng)自運(yùn)行的話有三個(gè)方法:

1、把它加到/etc/rc.local中

2、iptables-save >;/etc/sysconfig/iptables可以把你當(dāng)前的iptables規(guī)則放到/etc/sysconfig/iptables中,系統(tǒng)啟動(dòng)iptables時(shí)自動(dòng)執(zhí)行。

3、service iptables save 也可以把你當(dāng)前的iptables規(guī)則放/etc/sysconfig/iptables中,系統(tǒng)啟動(dòng)iptables時(shí)自動(dòng)執(zhí)行。

后兩種更好此,一般iptables服務(wù)會(huì)在network服務(wù)之前啟來(lái),更安全。

解封的話:
iptables -D INPUT -s IP地址 -j REJECT
iptables -F 全清掉了

Linux防火墻Iptable如何設(shè)置只允許某個(gè)ip訪問(wèn)80端口,只允許特定ip訪問(wèn)某端口?參考下面命令,只允許46.166.150.22訪問(wèn)本機(jī)的80端口。如果要設(shè)置其他ip或端口,改改即可。

?
1
2
iptables -I INPUT -p TCP –dport 80 -j DROP
iptables -I INPUT -s 46.166.150.22 -p TCP –dport 80 -j ACCEPT

在root用戶下執(zhí)行上面2行命令后,重啟iptables, service iptables restart

查看iptables是否生效:

?
1
2
3
4
5
6
7
8
9
10
11
[root@www.xxx.com]# iptables -L
Chain INPUT (policy ACCEPT)
target      prot opt source        destination
ACCEPT   tcp – 46.166.150.22  anywhere      tcp dpt:http
DROP     tcp – anywhere       anywhere      tcp dpt:http
 
Chain FORWARD (policy ACCEPT)
target   prot opt source        destination
 
Chain OUTPUT (policy ACCEPT)
target   prot opt source        destination

上面命令是針對(duì)整個(gè)服務(wù)器(全部ip)禁止80端口,如果只是需要禁止服務(wù)器上某個(gè)ip地址的80端口,怎么辦?

下面的命令是只允許來(lái)自174.140.3.190的ip訪問(wèn)服務(wù)器上216.99.1.216的80端口

?
1
2
iptables -A FORWARD -s 174.140.3.190 -d 216.99.1.216 -p tcp -m tcp –dport 80 -j ACCEPT
iptables -A FORWARD -d 216.99.1.216 -p tcp -m tcp –dport 80 -j DROP

更多iptables參考命令如下:

1.先備份iptables

?
1
# cp /etc/sysconfig/iptables /var/tmp

需要開80端口,指定IP和局域網(wǎng)

下面三行的意思:

先關(guān)閉所有的80端口

開啟ip段192.168.1.0/24端的80口

開啟ip段211.123.16.123/24端ip段的80口

?
1
2
3
# iptables -I INPUT -p tcp –dport 80 -j DROP
# iptables -I INPUT -s 192.168.1.0/24 -p tcp –dport 80 -j ACCEPT
# iptables -I INPUT -s 211.123.16.123/24 -p tcp –dport 80 -j ACCEPT

以上是臨時(shí)設(shè)置。

2.然后保存iptables

?
1
# service iptables save

3.重啟防火墻

?
1
#service iptables restart

以下是端口,先全部封再開某些的IP

?
1
2
iptables -I INPUT -p tcp –dport 9889 -j DROP
iptables -I INPUT -s 192.168.1.0/24 -p tcp –dport 9889 -j ACCEPT

如果用了NAT轉(zhuǎn)發(fā)記得配合以下才能生效

?
1
2
iptables -I FORWARD -p tcp –dport 80 -j DROP
iptables -I FORWARD -s 192.168.1.0/24 -p tcp –dport 80 -j ACCEPT

常用的IPTABLES規(guī)則如下:

只能收發(fā)郵件,別的都關(guān)閉

?
1
2
3
4
iptables -I Filter -m mac –mac-source 00:0F:EA:25:51:37 -j DROP
iptables -I Filter -m mac –mac-source 00:0F:EA:25:51:37 -p udp –dport 53 -j ACCEPT
iptables -I Filter -m mac –mac-source 00:0F:EA:25:51:37 -p tcp –dport 25 -j ACCEPT
iptables -I Filter -m mac –mac-source 00:0F:EA:25:51:37 -p tcp –dport 110 -j ACCEPT

IPSEC NAT 策略

?
1
2
3
4
5
6
iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp –dport 80 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.100.2:80
iptables -t nat -A PREROUTING -p tcp –dport 1723 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp –dport 1723 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp –dport 500 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.100.2:500
iptables -t nat -A PREROUTING -p udp –dport 4500 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.100.2:4500

FTP服務(wù)器的NAT

?
1
2
iptables -I PFWanPriv -p tcp –dport 21 -d 192.168.1.22 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp –dport 21 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.1.22:21

只允許訪問(wèn)指定網(wǎng)址

?
1
2
3
4
5
iptables -A Filter -p udp –dport 53 -j ACCEPT
iptables -A Filter -p tcp –dport 53 -j ACCEPT
iptables -A Filter -d www.ctohome.com -j ACCEPT
iptables -A Filter -d www.guowaivps.com -j ACCEPT
iptables -A Filter -j DROP

開放一個(gè)IP的一些端口,其它都封閉

?
1
2
3
4
5
6
7
iptables -A Filter -p tcp –dport 80 -s 192.168.1.22 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp –dport 25 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp –dport 109 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp –dport 110 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp –dport 53 -j ACCEPT
iptables -A Filter -p udp –dport 53 -j ACCEPT
iptables -A Filter -j DROP

多個(gè)端口

 

復(fù)制代碼 代碼如下:

iptables -A Filter -p tcp -m multiport –destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT

 

連續(xù)端口

 

復(fù)制代碼 代碼如下:

iptables -A Filter -p tcp -m multiport –source-port 22,53,80,110 -s 192.168.20.3 -j REJECT iptables -A Filter -p tcp –source-port 2:80 -s 192.168.20.3 -j REJECT

 

指定時(shí)間上網(wǎng)

?
1
2
3
iptables -A Filter -s 10.10.10.253 -m time –timestart 6:00 –timestop 11:00 –days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
iptables -A Filter -m time –timestart 12:00 –timestop 13:00 –days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
iptables -A Filter -m time –timestart 17:30 –timestop 8:30 –days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

禁止多個(gè)端口服務(wù)

?
1
iptables -A Filter -m multiport -p tcp –dport 21,23,80 -j ACCEPT

將WAN 口NAT到PC

 

復(fù)制代碼 代碼如下:

iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT –to-destination 192.168.0.1

 

將WAN口8000端口NAT到192。168。100。200的80端口

 

復(fù)制代碼 代碼如下:

iptables -t nat -A PREROUTING -p tcp –dport 8000 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.1.22:80

 

MAIL服務(wù)器要轉(zhuǎn)的端口

?
1
2
iptables -t nat -A PREROUTING -p tcp –dport 110 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.1.22:110
iptables -t nat -A PREROUTING -p tcp –dport 25 -d $INTERNET_ADDR -j DNAT –to-destination 192.168.1.22:25

只允許PING 202。96。134。133,別的服務(wù)都禁止

?
1
2
iptables -A Filter -p icmp -s 192.168.1.22 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -j DROP

禁用BT配置

?
1
iptables –A Filter –p tcp –dport 6000:20000 –j DROP

禁用QQ防火墻配置

?
1
2
3
4
iptables -A Filter -p udp –dport ! 53 -j DROP
iptables -A Filter -d 218.17.209.0/24 -j DROP
iptables -A Filter -d 218.18.95.0/24 -j DROP
iptables -A Filter -d 219.133.40.177 -j DROP

基于MAC,只能收發(fā)郵件,其它都拒絕

?
1
2
3
iptables -I Filter -m mac –mac-source 00:0A:EB:97:79:A1 -j DROP
iptables -I Filter -m mac –mac-source 00:0A:EB:97:79:A1 -p tcp –dport 25 -j ACCEPT
iptables -I Filter -m mac –mac-source 00:0A:EB:97:79:A1 -p tcp –dport 110 -j ACCEPT

禁用MSN配置

?
1
2
3
4
iptables -A Filter -p udp –dport 9 -j DROP
iptables -A Filter -p tcp –dport 1863 -j DROP
iptables -A Filter -p tcp –dport 80 -d 207.68.178.238 -j DROP
iptables -A Filter -p tcp –dport 80 -d 207.46.110.0/24 -j DROP

只允許PING 202。96。134。133 其它公網(wǎng)IP都不許PING

?
1
2
iptables -A Filter -p icmp -s 192.168.1.22 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -p icmp -j DROP

禁止某個(gè)MAC地址訪問(wèn)internet:

?
1
iptables -I Filter -m mac –mac-source 00:20:18:8F:72:F8 -j DROP

禁止某個(gè)IP地址的PING:

?
1
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

禁止某個(gè)IP地址服務(wù):

?
1
2
iptables –A Filter -p tcp -s 192.168.0.1 –dport 80 -j DROP
iptables –A Filter -p udp -s 192.168.0.1 –dport 53 -j DROP

只允許某些服務(wù),其他都拒絕(2條規(guī)則)

?
1
2
iptables -A Filter -p tcp -s 192.168.0.1 –dport 1000 -j ACCEPT
iptables -A Filter -j DROP

禁止某個(gè)IP地址的某個(gè)端口服務(wù)

?
1
2
iptables -A Filter -p tcp -s 10.10.10.253 –dport 80 -j ACCEPT
iptables -A Filter -p tcp -s 10.10.10.253 –dport 80 -j DROP

禁止某個(gè)MAC地址的某個(gè)端口服務(wù)

?
1
iptables -I Filter -p tcp -m mac –mac-source 00:20:18:8F:72:F8 –dport 80 -j DROP

禁止某個(gè)MAC地址訪問(wèn)internet:

?
1
iptables -I Filter -m mac –mac-source 00:11:22:33:44:55 -j DROP

禁止某個(gè)IP地址的PING:

?
1
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://yusi123.com/3092.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 草久在线视频 | 亚洲国产精品yw在线观看 | 国产在线视频一区 | 亚洲综合激情网 | 亚洲一区免费视频 | 欧美在线观看黄 | 日韩成人在线视频 | 奇米久久 | www.午夜 | 国产精品日本 | 国产午夜精品一区二区三区嫩草 | 日韩视频在线免费观看 | 国产成人高清在线 | 欧美精品 | av大片网| 亚洲一区二区三区四区在线 | 九九在线精品视频 | 亚洲欧美一区二区视频 | 理论电影在线 | 久久国产欧美日韩精品 | 日韩视频一区 | 毛片aaa | 久久久久久婷婷 | 日韩欧美视频免费 | 国产欧美日韩综合精品 | 91av在线免费播放 | 97人人看 | 国产精品免费网址 | 久久视频精品 | 99在线免费视频 | 美女视频黄色片 | 久久99久| 蜜桃精品久久久久久久免费影院 | 国产精品毛片一区视频播不卡 | 欧美精品一区三区 | 日韩三级电影在线观看 | 久久久国产一区 | 色婷婷国产精品免费网站 | 亚洲欧美激情精品一区二区 | 国产特级毛片aaaaaa毛片 | 国产视频第一页 |