国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【linux】iptables和ufw禁用IP和端口

這篇具有很好參考價(jià)值的文章主要介紹了【linux】iptables和ufw禁用IP和端口。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

引言

有時(shí)候服務(wù)器,為了安全需要,會(huì)限制某些ip和端口對服務(wù)器的訪問。那具體該如何配置呢?本文帶你解決。
ubuntu 禁用端口,計(jì)算機(jī)技術(shù),linux,ubuntu,tcp/ip,linux

禁用IP和端口

1、方法1:iptables

iptables v1.8.4

Usage: iptables -[ACD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)

Commands:
Either long or short options are allowed.
  --append  -A chain            Append to chain
  --check   -C chain            Check for the existence of a rule
  --delete  -D chain            Delete matching rule from chain
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain
  --insert  -I chain [rulenum]
                                Insert in chain as rulenum (default 1=first)
  --replace -R chain rulenum
                                Replace rule rulenum (1 = first) in chain
  --list    -L [chain [rulenum]]
                                List the rules in a chain or all chains
  --list-rules -S [chain [rulenum]]
                                Print the rules in a chain or all chains
  --flush   -F [chain]          Delete all rules in  chain or all chains
  --zero    -Z [chain [rulenum]]
                                Zero counters in chain or all chains
  --new     -N chain            Create a new user-defined chain
  --delete-chain
            -X [chain]          Delete a user-defined chain
  --policy  -P chain target
                                Change policy on chain to target
  --rename-chain
            -E old-chain new-chain
                                Change chain name, (moving any references)
Options:
    --ipv4      -4              Nothing (line is ignored by ip6tables-restore)
    --ipv6      -6              Error (line is ignored by iptables-restore)
[!] --protocol  -p proto        protocol: by number or name, eg. `tcp'
[!] --source    -s address[/mask][...]
                                source specification
[!] --destination -d address[/mask][...]
                                destination specification
[!] --in-interface -i input name[+]
                                network interface name ([+] for wildcard)
 --jump -j target
                                target for rule (may load target extension)
  --goto      -g chain
                              jump to chain with no return
  --match       -m match
                                extended match (may load extension)
  --numeric     -n              numeric output of addresses and ports
[!] --out-interface -o output name[+]
                                network interface name ([+] for wildcard)
  --table       -t table        table to manipulate (default: `filter')
  --verbose     -v              verbose mode
  --wait        -w [seconds]    maximum wait to acquire xtables lock before give up
  --wait-interval -W [usecs]    wait time to try to acquire xtables lock
                                default is 1 second
  --line-numbers                print line numbers when listing
  --exact       -x              expand numbers (display exact values)
[!] --fragment  -f              match second or further fragments only
  --modprobe=<command>          try to insert modules using this command
  --set-counters PKTS BYTES     set the counter during insert/append
[!] --version   -V              print package version.

  • ??端口
iptables -A INPUT -p tcp --dport 80 -j DROP
iptables -A INPUT -p tcp --dport 5053 -j DROP
  • ??IP
iptables -I INPUT -s 10.115.10.129 -j DROP
  • 保存配置
    sudo service iptables save
    實(shí)測這條命令行不通,報(bào)錯(cuò):iptables: unrecognized service
    下面這條可以
sudo iptables-save

2、方法2:ufw

UFW (Uncomplicated Firewall)是Ubuntu 自帶的防火墻配置工具 。UFW 是一個(gè)用來管理 iptables 防火墻規(guī)則的用戶友好的前端工具。它的主要目的就是為了使得管理 iptables 更簡單。

Usage: ufw COMMAND

Commands:
 enable                          enables the firewall
 disable                         disables the firewall
 default ARG                     set default policy
 logging LEVEL                   set logging to LEVEL
 allow ARGS                      add allow rule
 deny ARGS                       add deny rule
 reject ARGS                     add reject rule
 limit ARGS                      add limit rule
 delete RULE|NUM                 delete RULE
 insert NUM RULE                 insert RULE at NUM
 route RULE                      add route RULE
 route delete RULE|NUM           delete route RULE
 route insert NUM RULE           insert route RULE at NUM
 reload                          reload firewall
 reset                           reset firewall
 status                          show firewall status
 status numbered                 show firewall status as numbered list of RULES
 status verbose                  show verbose firewall status
 show ARG                        show firewall report
 version                         display version information

Application profile commands:
 app list                        list application profiles
 app info PROFILE                show information on PROFILE
 app update PROFILE              update PROFILE
 app default ARG                 set default application policy

Ubuntu安裝完畢,默認(rèn)沒有啟動(dòng)ufw。所以如果直接運(yùn)行上述語句,那么它啟動(dòng)后就會(huì)使用默認(rèn)規(guī)則,禁止一切流量,包括SSH的22端口,如果本來就是在SSH上遠(yuǎn)程操作,那么悲劇了,所以要先啟用SSH的端口(默認(rèn)是22,如果你設(shè)置了其他端口就加上去)

sudo ufw allow 22
sudo ufw reject 80 #(拒絕,直接返回:Connection refused)
sudo ufw deny 5053 #(否認(rèn),過段時(shí)間后返回:Connection timed out)
sudo ufw enable
sudo ufw status
  • 查看ufw防火墻是否在工作,查看使用中的規(guī)則
ufw status
  • 啟動(dòng)/關(guān)閉/重置ufw防火墻
ufw enable
ufw disable
ufw reset
  • 允許其它主機(jī)訪問本機(jī)21端口,協(xié)議包含tcp和udp
ufw allow 21

-允許其它主機(jī)使用tcp協(xié)議訪問本機(jī)80端口

ufw allow 80/tcp
  • 可以使用in或out來指定向內(nèi)還是向外。如果未指定,默認(rèn)是in
    允許訪問本機(jī)http端口
ufw allow in http
  • 禁止其它主機(jī)訪問本機(jī)80端口,
    • reject,直接告訴拒絕,返回的提示信息更多,比如ssh該主機(jī)時(shí),直接返回:Connection refused

    • deny,否認(rèn),返回的提示信息少,比如ssh該主機(jī)時(shí),過段時(shí)間后才返回:Connection timed out

ufw reject 80
ufw deny 80
  • 禁止本機(jī)對外訪問192.168.1.1
    (實(shí)測有用)
ufw deny out to 192.168.1.1
  • 禁止192.168.1.1對內(nèi)訪問本機(jī)
    (實(shí)測沒用)
ufw deny from 192.168.1.1
  • 刪除規(guī)則,只要在命令中加入delete就行了
ufw delete deny 80/tcp
  • 打開/關(guān)閉log
ufw logging on
ufw logging off

logging on后 默認(rèn)是low 等級。ufw支持多個(gè)等級: ‘low’, ‘medium’, ‘high’ and ‘full’。簡單說low記錄事件做少,其他等級記錄逐級增加。使用默認(rèn)的low level就夠了。log文件保存在/var/log/ufw.log 文件內(nèi),可以用tail -n COUNT file的形式顯示最后幾行

參考文檔

Linux下iptables屏蔽IP和端口號
Ubuntu 18.04 防火墻設(shè)置ufw詳解
如何在 Ubuntu 20.04 上使用 UFW 來設(shè)置防火墻
Ubuntu自帶防火墻ufw配置和用法文章來源地址http://www.zghlxwxcb.cn/news/detail-655492.html

到了這里,關(guān)于【linux】iptables和ufw禁用IP和端口的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • iptables -nvL查看linux系統(tǒng)的所有ip和端口情況

    1、查看規(guī)則 對規(guī)則的查看需要使用如下命令: 各參數(shù)的含義為: -L 表示查看當(dāng)前表的所有規(guī)則,默認(rèn)查看的是 filter 表,如果要查看 nat 表,可以加上 -t nat 參數(shù)。 -n 表示不對 IP 地址進(jìn)行反查,加上這個(gè)參數(shù)顯示速度將會(huì)加快。 -v 表示輸出詳細(xì)信息,包含通過該規(guī)則的數(shù)據(jù)

    2024年02月12日
    瀏覽(35)
  • Linux【安全 01】云服務(wù)器主機(jī)安全加固(修改SSHD端口、禁用登陸失敗的IP地址、使用密鑰登錄)

    Linux【安全 01】云服務(wù)器主機(jī)安全加固(修改SSHD端口、禁用登陸失敗的IP地址、使用密鑰登錄)

    修改SSHD的默認(rèn)端口,它可以抵御一些簡單的密碼暴力破解腳本。 查看登錄失敗的IP地址 通過下面的命令將這些登陸失敗的IP加入服務(wù)器訪問限制名單【失敗次數(shù)最多的10個(gè)IP】 使用SSH密鑰,并禁用密碼登錄,以MobaXterm為例進(jìn)行說明。 以下命令在本機(jī)上執(zhí)行(Windows) 使用Mob

    2024年02月05日
    瀏覽(20)
  • iptables指定ip訪問指定端口

    iptables指定ip訪問指定端口

    2024年02月08日
    瀏覽(26)
  • iptables修改目的IP和端口

    iptables NAT表的OUTPUT鏈用于對由本機(jī)發(fā)起的數(shù)據(jù)包進(jìn)行目標(biāo)IP地址和端口號的修改。DNAT指令可以用于將數(shù)據(jù)包的目標(biāo)IP地址和端口號替換為指定的IP地址和端口號。在OUTPUT鏈中使用DNAT指令可以實(shí)現(xiàn)對本機(jī)發(fā)送的數(shù)據(jù)包進(jìn)行目標(biāo)地址的轉(zhuǎn)換,將數(shù)據(jù)包發(fā)送至指定的目標(biāo)地址。用法

    2024年02月05日
    瀏覽(24)
  • iptables只允許指定IP調(diào)用所有端口

    ????????首先需要設(shè)置一下允許所有ip訪問22端口,要不然ssh就連不上了 ? ? ? ? 當(dāng)本機(jī)允許程序時(shí),可能會(huì)訪問到本機(jī)mysql、redis等數(shù)據(jù)庫,所以需要允許本機(jī)ip訪問

    2024年02月10日
    瀏覽(24)
  • [運(yùn)維] iptables限制指定ip訪問指定端口和只允許指定ip訪問指定端口

    要使用 iptables 限制特定IP地址訪問特定端口,您可以使用以下命令: 請將 IP地址 替換為要限制的IP地址,將 端口號 替換為要限制的端口號。 這個(gè)命令將添加一條規(guī)則到 iptables 的 INPUT 鏈,該規(guī)則匹配特定的 IP 地址和端口號,并將數(shù)據(jù)包的動(dòng)作設(shè)置為 DROP ,這意味著數(shù)據(jù)包將

    2024年02月12日
    瀏覽(19)
  • iptables防火墻屏蔽指定ip的端口

    iptables防火墻屏蔽指定ip的端口

    因?yàn)樾枰獪y試客戶端程序與hadoop服務(wù)器之間正常通信需要開通的端口, 所以在hadoop各服務(wù)器上使用iptables防火墻屏蔽了測試客戶端程序的ip和所有端口。然后,根據(jù)報(bào)錯(cuò)信息提示的端口號來逐步放開直到能正常通信下載文件。 在服務(wù)器端屏蔽指定ip訪問所有端口 測試客戶端程序

    2024年02月04日
    瀏覽(30)
  • iptables 限制所有ip訪問22端口,僅開放個(gè)別ip訪問 持續(xù)更新

    iptables 限制所有ip訪問22端口,僅開放個(gè)別ip訪問 持續(xù)更新

    查看當(dāng)前iptables 規(guī)則 添加已經(jīng)建立tcp連接,就開放網(wǎng)絡(luò)訪問 添加允許訪問22端口的ip 拒絕所有ip訪問22端口 新加一個(gè)ip訪問該主機(jī)22端口 保存iptables規(guī)則 參數(shù)詳解 效果 本文參考:https://blog.csdn.net/zhougubei/article/details/120350467 本文參考:https://blog.csdn.net/qq_44273583/article/details/116661

    2024年02月07日
    瀏覽(25)
  • iptables拒絕所有端口放開特定端口方法流程,iptables允許ping和拒絕ping、hosts阻止所有ip指定放開ip方法流程、腳本檢測日志異常并自動(dòng)執(zhí)行封堵

    iptables拒絕所有端口放開特定端口方法流程,iptables允許ping和拒絕ping、hosts阻止所有ip指定放開ip方法流程、腳本檢測日志異常并自動(dòng)執(zhí)行封堵

    收到下面一封郵件,簡單來說就是需要一個(gè)虛擬機(jī),外網(wǎng)能ping同,但端口全封,給他們做滲透用。 問了需求 不需要登錄,封死所有端口。 所以 就用下面2個(gè)方式雙重封死。 命令: iptables -P INPUT DROP 【我這就執(zhí)行了這個(gè)進(jìn)的】 iptables -P FORWARD DROP iptables -P OUTPUT DROP 注:上面執(zhí)

    2024年02月05日
    瀏覽(29)
  • Ceph入門到精通-iptables 限制多個(gè)ip 的多個(gè)端口段訪問

    要使用iptables限制多個(gè)IP的多個(gè)端口范圍的訪問,可以使用以下命令: 上面的命令將添加一條規(guī)則到INPUT鏈中,該規(guī)則將禁止指定IP范圍訪問指定的端口段。其中, 端口段 是指你要限制的端口范圍,例如:80:100表示限制80到100的端口范圍; 起始IP-結(jié)束IP 是指你要限制的IP范圍,

    2024年02月04日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包