<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          iptables限制ssh鏈接服務(wù)器

          共 1613字,需瀏覽 4分鐘

           ·

          2024-06-21 08:00

          Linux服務(wù)器默認(rèn)通過22端口用ssh協(xié)議登錄,這種不安全。今天想做限制,即允許部分來源ip連接服務(wù)器。

          案例目標(biāo):通過iptables規(guī)則限制對(duì)linux服務(wù)器的登錄。

          處理方法:編寫為sh腳本,以便多次執(zhí)行。iptables.sh :

          iptables -I INPUT -p tcp --dport 22 -j DROP -m comment --comment "ssh"
          # 按ip范圍區(qū)間開放
          iptables -I INPUT -p tcp -m iprange --src-range 172.18.163.227-172.18.163.232 --dport 22 -j ACCEPT -m comment --comment "ssh"

          # 按網(wǎng)段開放
          iptables -I INPUT -p tcp -s 10.99.193.0/24 --dport 22 -j ACCEPT -m comment --comment "ssh"

          簡(jiǎn)要說明:這里默認(rèn)使用filter表的INPUT鏈,使用-I插入方式,第一條DROP操作順序不能錯(cuò),必須是首條。

          對(duì)于已經(jīng)插入的規(guī)則,可以使用下面的命令進(jìn)行查看:

          iptables -t filter -nvL --line-number |grep ssh

          如果后面需要?jiǎng)h除規(guī)則,可以按照下面的方式處理:

          iptables -t filter -D INPUT 3

          說明一下:這里刪除iptables規(guī)則,指定了filter表的INPUT鏈,避免出錯(cuò)。
          根據(jù)上一步查看的規(guī)則的行號(hào)來刪除,查看到相應(yīng)的規(guī)則編號(hào)之后,最好從最大的編號(hào)開始逐條刪除。

          示例:禁止所有類型鏈接,允許特別定來源ip鏈接 iptables-myrules.sh

          #! /bin/bash
          # author: xiongzaiqiren
          # date: 2023-03-20
          # usage: sh iptables-myrules.sh
          # 設(shè)置服務(wù)器安全,允許特定來源ip訪問請(qǐng)執(zhí)行我。
          # 每次改完需要執(zhí)行iptables-save > /etc/iptables-myrules.conf 備份規(guī)則哦

          #允許ping
          iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

          # 拒絕所有鏈接
          iptables -P INPUT DROP;

          # 指定ip及范圍允許鏈接
          iptables -A INPUT -s 10.99.193.243 -p tcp -j ACCEPT
          iptables -A INPUT -s 10.90.5.0/24 -p tcp -j ACCEPT
          iptables -A INPUT -s 10.99.193.0/24 -p tcp -j ACCEPT

          iptables -nvL --line-numbers
          #iptables -t filter -D INPUT 3 #表示刪除filter表中的FORWARD鏈的第一條規(guī)則

          鏈接:https://www.cnblogs.com/xiongzaiqiren/p/iptables-ssh.html

                                                                        (版權(quán)歸原作者所有,侵刪)

          瀏覽 77
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  小黄片免费下载 | 想看操逼视频 | 黄色无码视频在线免费观看 | 欧美日色 | A片网站免费黄色 |