как разрешить трафик на определённых IP для порта в iptables

Я хочу ограничить трафик для всех IP, кроме 10.2.3.4 на порту 5041

Сначала я дал доступ к IP на порту так :

iptables -A IN_public_allow -s 10.2.3. 4 -p tcp -m tcp --dport 5041 -m conntrack --ctstate NEW -j ACCEPT

Затем я ограничил доступ для всех IP:

iptables -A IN_public_allow -p tcp -m tcp --dport 5041 -m conntrack --ctstate NEW -j DROP

Так что теоретически я должен был иметь доступ к порту только с IP 10.2.3.4, но это не так. Я использую ncat для проверки этого, используя опцию -s для изменения адреса источника :

ncat.exe -s 10.2.3.5 -zv  10.78.21.51 5041
libnsock mksock_bind_addr(): Bind to 10.2.3.5:0 failed (IOD #1): The requested address is not valid in its context.  (10049)
Ncat: Connected to :10.78.21.51:5041.
Ncat: 0 bytes sent, 0 bytes received in 0.12 seconds

Таким образом, команда выглядит так, как будто она подключена к порту с IP 10.2.3.5, хотя и не должна была. Я не знаю, что libnsock mksock_bind_addr(): Ошибка привязки к 10.2.3.5:0 failed. Пожалуйста, помогите, спасибо.

EDIT : вывод команды iptables -xvnL по запросу :

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
642614522 702873881336 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
  454146 27240797 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
  392972 20241510 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0
  392972 20241510 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0
  392972 20241510 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       3      120 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    4070   483366 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
       0        0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
       0        0 FORWARD_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FORWARD_IN_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FORWARD_IN_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FORWARD_OUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FORWARD_OUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
       0        0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 326255 packets, 205303698 bytes)
    pkts      bytes target     prot opt in     out     source               destination
488899038 266093163662 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD_IN_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 FWDI_public  all  --  bond1  *       0.0.0.0/0            0.0.0.0/0           [goto]
       0        0 FWDI_public  all  --  bond0  *       0.0.0.0/0            0.0.0.0/0           [goto]
       0        0 FWDI_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto]

Chain FORWARD_IN_ZONES_SOURCE (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FORWARD_OUT_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 FWDO_public  all  --  *      bond1   0.0.0.0/0            0.0.0.0/0           [goto]
       0        0 FWDO_public  all  --  *      bond0   0.0.0.0/0            0.0.0.0/0           [goto]
       0        0 FWDO_public  all  --  *      +       0.0.0.0/0            0.0.0.0/0           [goto]

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FORWARD_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDI_public (3 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 FWDI_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FWDI_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FWDI_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FWDI_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDI_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDI_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDO_public (3 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 FWDO_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FWDO_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 FWDO_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FWDO_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDO_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain FWDO_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain INPUT_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination
    4307   492298 IN_public  all  --  bond1  *       0.0.0.0/0            0.0.0.0/0           [goto]
  388631 19744052 IN_public  all  --  bond0  *       0.0.0.0/0            0.0.0.0/0           [goto]
      34     5160 IN_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto]

Chain INPUT_ZONES_SOURCE (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain INPUT_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain IN_public (3 references)
    pkts      bytes target     prot opt in     out     source               destination
  392972 20241510 IN_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0
  392972 20241510 IN_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0
  392972 20241510 IN_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0
       0        0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0

Chain IN_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3179 ctstate NEW
    2477   145924 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5534 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5524 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8434 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5056 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3189 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW
       0        0 ACCEPT     tcp  --  *      *       10.2.3.4        0.0.0.0/0            tcp dpt:5041 ctstate NEW
       5      260 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5041 ctstate NEW

Chain IN_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain IN_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination

0
задан 6 March 2021 в 16:49

1 ответ

ОК, поэтому после некоторых проверок я обнаружил, что правила iptables отфильтровали IP-пакеты именно то, как я хочу, проблема в том, что команда netcat ncat.exe -s 10.2.3.5 -zv 10.78.21.51 5041 На самом деле не меняет исходный адрес как опция PE «-S», он все еще использует адрес источника по умолчанию. Один из них знает, как Telnet использует другой исходный адрес? Это возможно?

0
ответ дан 18 March 2021 в 23:28

Другие вопросы по тегам:

Похожие вопросы: