AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 1293862
Accepted
bomben
bomben
Asked: 2020-11-21 01:42:21 +0800 CST2020-11-21 01:42:21 +0800 CST 2020-11-21 01:42:21 +0800 CST

Por que o iptables -F está me expulsando da minha sessão ssh?

  • 772

Eu queria adicionar algumas regras ao iptables desta pergunta e respostas para rotear o tráfego do programa torrent Transmissão através de uma vpn (surfshark no meu caso).

Pelo menos duas das respostas são usadas iptables -Fpara liberar as tabelas antes de adicionar as regras personalizadas.

Uma dessas respostas faz referência especificamente a um servidor sem cabeça (como o meu). Então eu suspeito que isso deve funcionar.

Mas se eu usar iptables -F, sou instantaneamente expulso da minha sessão ssh para o servidor. Não consigo digitar nenhum novo comando no terminal e preciso reinicializar o servidor para fazer login novamente.

Eu tenho um firewall rodando no servidor que permite a porta 22 para cada IP.


Para esclarecimento, adicionarei algumas saídas de antes e depois de aplicar a resposta aceita:

Antes (aviso policy DROP):

     $ sudo iptables -xvnL
Chain INPUT (policy DROP 21 packets, 5628 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
     387    31969 f2b-sshd   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 22
   27008 50413306 ufw-before-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   27008 50413306 ufw-before-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     153    26176 ufw-after-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
      21     5628 ufw-after-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
      21     5628 ufw-reject-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
      21     5628 ufw-track-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy DROP 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 ufw-before-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-before-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-reject-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-track-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 7 packets, 324 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
    7130   870596 ufw-before-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    7130   870596 ufw-before-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     997   113175 ufw-after-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     997   113175 ufw-after-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     997   113175 ufw-reject-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     997   113175 ufw-track-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0      

 

Depois:

 $ sudo iptables -L -v
Chain INPUT (policy ACCEPT 12648 packets, 12M bytes)

Isso é depois que eu configurei para policy ACCEPT, depois limpei, adicionei as regras transmission-daemonda outra resposta aqui e fiz essa configuração persistir após a reinicialização com sudo dpkg-reconfigure iptables-persistent, reinicializar e fazer login no ssh. Agora eu gostaria, policy DROPmas isso vai me expulsar novamente.

Talvez interessante: eu desativei o ufwfirewall só para ter certeza. Depois que eu o reativei, ele também me expulsou (enquanto policy ACCEPT). Claro que eu tinha uma allow 22regra. Eu tive que reiniciar e então eu poderia fazer login novamente com o firewall funcionando.

Não tenho conhecimento iptablese com certeza vou pesquisar. Não sei como ativar o firewall pode me expulsar se a política principal for ACCEPTe o firewall tiver um arquivo 22.

 $ sudo iptables -xvnL
[sudo] Passwort für ben: 
Chain INPUT (policy ACCEPT 34981 packets, 9871660 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
     121    15110 f2b-sshd   tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 22
       0        0 ACCEPT     all  --  tun0   *       0.0.0.0/0            0.0.0.0/0           
       0        0 ACCEPT     all  --  eth0   *       0.0.0.0/0            0.0.0.0/0           
     134    12445 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy DROP 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0            all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 19730 packets, 3108705 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 ACCEPT     tcp  --  *      eth0    0.0.0.0/0            192.168.100.0/25     tcp spt:9091 owner GID match 136
       0        0 ACCEPT     udp  --  *      eth0    0.0.0.0/0            192.168.100.0/25     udp spt:9091 owner GID match 136
       0        0 ACCEPT     all  --  *      tun0    0.0.0.0/0            0.0.0.0/0            owner GID match 136
       0        0 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0            owner GID match 136
       0        0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            owner GID match 136 reject-with icmp-port-unreachable

Chain f2b-sshd (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
     121    15110 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-after-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-logging-allow (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-logging-deny (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-not-local (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-skip-to-policy-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-skip-to-policy-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-skip-to-policy-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-limit (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-limit-accept (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-logging-forward (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-logging-input (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-logging-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-user-output (0 references)
    pkts      bytes target     prot opt in     out     source               destination 

Aqui as regras de firewall:

$ sudo ufw status
Status: Aktiv

Zu                         Aktion      Von
--                         ------      ---
22                         ALLOW       192.168.100.0/24          
5900                       ALLOW       192.168.100.0/24           # vnc
1900                       ALLOW       192.168.100.0/24           # minidlna
8200                       ALLOW       192.168.100.0/24           # minidlna
445                        ALLOW       192.168.100.0/24           # cifs
5901                       ALLOW       192.168.100.0/24           # vnc
5902                       ALLOW       192.168.100.0/24           # vnc

Uma coisa adicional: eu tenho uma eth0interface? Meu mini PC ZOTAC tem duas conexões ethernet e fiquei confuso que eth0não aparece. O script para definir as regras usa IFACE_INTERNAL=eth0. Isso poderia ser um problema?

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:01:2e:4d:52:96 brd ff:ff:ff:ff:ff:ff
3: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:01:2e:4d:52:9b brd ff:ff:ff:ff:ff:ff
4: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 0c:d2:92:57:c2:53 brd ff:ff:ff:ff:ff:ff
networking server iptables ssh firewall
  • 1 1 respostas
  • 534 Views

1 respostas

  • Voted
  1. Best Answer
    Doug Smythies
    2020-11-21T08:14:44+08:002020-11-21T08:14:44+08:00

    Sim, o The iptables -F chainliberará todas as regras do iptables para essa cadeia e, portanto, apenas a regra de política padrão será usada.

    Parece provável que a política padrão para suas referências era ACCEPT, enquanto a política padrão em seu computador é DROP.

    Verifique através de sudo iptables -xvnL. Se você deseja excluir todas as suas regras em uma cadeia, mas manter sua sessão ssh, altere a política padrão para ACCEPTfirst. Você pode alterá-lo de volta para DROPdepois de ter as regras que deseja em vigor e confirmar que seus pacotes ssh não dependem mais da política padrão para passar.

    sudo iptables -P INPUT ACCEPT
    

    Você pode precisar dele na cadeia OUTPUT também.

    • 3

relate perguntas

  • Como interagir graficamente com um servidor sem cabeça?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve