NAT para segunda interface na rede privada

0

Eu tenho o seguinte configurado para minhas duas interfaces de rede.

eth1 10.93.90.1 (Rede de Produção)
eth0 192.160.0.1 (rede privada / rede Labb)

Eu quero configurar a eth0 com NAT para que eu possa me comunicar através da eth1 na rede de produção.

Isso é o que eu tentei:

[email protected] # echo 1 > /proc/sys/net/ipv4/ip_forward
[email protected] # iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
[email protected] # iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
[email protected] # iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

Mas o nó que está conectado à interface eth0 com o endereço IP 192.168.0.236 não pode se comunicar com outros nós na rede de produção (10.0.0.0). Pode, no entanto, comunicar com o host:

[email protected] # ping 10.93.90.1
10.93.90.1 is alive!

Mas nenhum outro host na rede de produção:

[email protected] # ping 10.93.89.1
No response from 10.93.89.1

Isso funciona bem quando faço ping do próprio host:

[email protected] # ping 10.93.89.1
PING 10.93.89.1 (10.93.89.1) 56(84) bytes of data.

Estou sentindo falta de algo aqui? Ou isso não é possível apenas com o uso do NAT?

UPDATE 1

Tabela de roteamento para o host eth1 (10.93.90.1):

[email protected] # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use   Iface
default         fafne-vlan93.se 0.0.0.0         UG    0      0        0     eth1
10.93.0.0       *               255.255.0.0     U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

Tabela de roteamento para o host eth0 (192.168.0.236)

[email protected] # ip route list
default via 192.168.0.1 dev eth0 
default dev eth0  scope link  metric 99 
169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.221.167 
169.254.0.0/16 dev eth0  scope link  metric 99 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.236

UPDATE 2

Alterei a seguinte regra:

iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

Para:

iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

Eu também adicionei a seguinte regra para depurar o ping:

iptables -I FORWARD -j LOG --log-prefix 'SNOOP_'

E aqui está o que foi registrado quando eu pinguei de 192.168.0.236 para 10.93.89.1:

Apr  1 09:14:44 lnxchrispet kernel: [2415274.711664] SNOOP_IN=eth0 OUT=eth1 MAC=90:e2:ba:3c:87:c4:ac:cc:8e:37:47:a6:08:00 SRC=192.168.0.236 DST=10.93.89.1 LEN=84 TOS=0x00 PREC=0x00 TTL=63 ID=9639 DF PROTO=ICMP TYPE=8 CODE=0 ID=0 SEQ=0
Apr  1 09:14:44 lnxchrispet kernel: [2415274.711935] SNOOP_IN=eth1 OUT=eth0 MAC=7c:05:07:0e:36:03:70:54:d2:7c:45:be:08:00 SRC=10.93.89.1 DST=192.168.0.236 LEN=84 TOS=0x00 PREC=0x00 TTL=63 ID=58826 PROTO=ICMP TYPE=0 CODE=0 ID=0 SEQ=0

UPDATE 3

Estes são todos os módulos carregados do kernel para o nat:

[email protected] # lsmod |grep nat
iptable_nat            12928  1 
nf_nat                 18231  2 iptable_nat,ipt_MASQUERADE
nf_conntrack_ipv4      14078  3 nf_nat,iptable_nat
nf_conntrack           52720  5 nf_conntrack_ipv4,nf_nat,iptable_nat,ipt_MASQUERADE,xt_state
ip_tables              22042  2 iptable_nat,iptable_filter
x_tables               19118  6 ip_tables,iptable_nat,ipt_MASQUERADE,iptable_filter,xt_state,ipt_LOG

Este módulo parece estar faltando, é relevante?

nf_nat_ipv4

Eu tentei carregá-lo, mas parece que não funcionam:

[email protected] # modprobe -v nf_nat_ipv4
[email protected] # lsmod |grep nat
iptable_nat            12928  1 
nf_nat                 18231  2 iptable_nat,ipt_MASQUERADE
nf_conntrack_ipv4      14078  3 nf_nat,iptable_nat
nf_conntrack           52720  5 nf_conntrack_ipv4,nf_nat,iptable_nat,ipt_MASQUERADE,xt_state
ip_tables              22042  2 iptable_nat,iptable_filter
x_tables               19118  6 ip_tables,iptable_nat,ipt_MASQUERADE,iptable_filter,xt_state,ipt_LOG

UPDATE 4

Algo não parece certo, faltam os módulos relacionados a NAT:

[email protected] # ls -l /lib/modules/3.2.0-4-amd64/kernel/net/netfilter
total 1076
drwxr-xr-x 2 root root   4096 Mar  4 06:42 ipset
drwxr-xr-x 2 root root   4096 Mar  4 06:42 ipvs
-rw-r--r-- 1 root root  10416 Feb 29 18:10 nf_conntrack_amanda.ko
-rw-r--r-- 1 root root   4336 Feb 29 18:10 nf_conntrack_broadcast.ko
-rw-r--r-- 1 root root  14440 Feb 29 18:10 nf_conntrack_ftp.ko
-rw-r--r-- 1 root root  67360 Feb 29 18:10 nf_conntrack_h323.ko
-rw-r--r-- 1 root root  12944 Feb 29 18:10 nf_conntrack_irc.ko
-rw-r--r-- 1 root root 116096 Feb 29 18:10 nf_conntrack.ko
-rw-r--r-- 1 root root   5552 Feb 29 18:10 nf_conntrack_netbios_ns.ko
-rw-r--r-- 1 root root  32528 Feb 29 18:10 nf_conntrack_netlink.ko
-rw-r--r-- 1 root root  14416 Feb 29 18:10 nf_conntrack_pptp.ko
-rw-r--r-- 1 root root  16672 Feb 29 18:10 nf_conntrack_proto_dccp.ko
-rw-r--r-- 1 root root  11912 Feb 29 18:10 nf_conntrack_proto_gre.ko
-rw-r--r-- 1 root root  15192 Feb 29 18:10 nf_conntrack_proto_sctp.ko
-rw-r--r-- 1 root root   8992 Feb 29 18:10 nf_conntrack_proto_udplite.ko
-rw-r--r-- 1 root root  10664 Feb 29 18:10 nf_conntrack_sane.ko
-rw-r--r-- 1 root root  36480 Feb 29 18:10 nf_conntrack_sip.ko
-rw-r--r-- 1 root root   6352 Feb 29 18:10 nf_conntrack_snmp.ko
-rw-r--r-- 1 root root  10240 Feb 29 18:10 nf_conntrack_tftp.ko
-rw-r--r-- 1 root root  11400 Feb 29 18:10 nfnetlink.ko
-rw-r--r-- 1 root root  20120 Feb 29 18:10 nfnetlink_log.ko
-rw-r--r-- 1 root root  18920 Feb 29 18:10 nfnetlink_queue.ko
-rw-r--r-- 1 root root   4952 Feb 29 18:10 nf_tproxy_core.ko
-rw-r--r-- 1 root root  44016 Feb 29 18:10 x_tables.ko
-rw-r--r-- 1 root root   6904 Feb 29 18:10 xt_addrtype.ko
-rw-r--r-- 1 root root   7688 Feb 29 18:10 xt_AUDIT.ko
-rw-r--r-- 1 root root   4912 Feb 29 18:10 xt_CHECKSUM.ko
-rw-r--r-- 1 root root   4384 Feb 29 18:10 xt_CLASSIFY.ko
-rw-r--r-- 1 root root   5440 Feb 29 18:10 xt_cluster.ko
-rw-r--r-- 1 root root   4144 Feb 29 18:10 xt_comment.ko
-rw-r--r-- 1 root root   5480 Feb 29 18:10 xt_connbytes.ko
-rw-r--r-- 1 root root   8776 Feb 29 18:10 xt_connlimit.ko
-rw-r--r-- 1 root root   6560 Feb 29 18:10 xt_connmark.ko
-rw-r--r-- 1 root root   6272 Feb 29 18:10 xt_CONNSECMARK.ko
-rw-r--r-- 1 root root   7032 Feb 29 18:10 xt_conntrack.ko
-rw-r--r-- 1 root root   4400 Feb 29 18:10 xt_cpu.ko
-rw-r--r-- 1 root root   7232 Feb 29 18:10 xt_CT.ko
-rw-r--r-- 1 root root   6376 Feb 29 18:10 xt_dccp.ko
-rw-r--r-- 1 root root   4352 Feb 29 18:10 xt_devgroup.ko
-rw-r--r-- 1 root root   5448 Feb 29 18:10 xt_dscp.ko
-rw-r--r-- 1 root root   6176 Feb 29 18:10 xt_DSCP.ko
-rw-r--r-- 1 root root   4704 Feb 29 18:10 xt_esp.ko
-rw-r--r-- 1 root root  17592 Feb 29 18:10 xt_hashlimit.ko
-rw-r--r-- 1 root root   5280 Feb 29 18:10 xt_helper.ko
-rw-r--r-- 1 root root   4472 Feb 29 18:10 xt_hl.ko
-rw-r--r-- 1 root root   5896 Feb 29 18:10 xt_HL.ko
-rw-r--r-- 1 root root  10888 Feb 29 18:10 xt_IDLETIMER.ko
-rw-r--r-- 1 root root   4848 Feb 29 18:10 xt_iprange.ko
-rw-r--r-- 1 root root   5672 Feb 29 18:10 xt_ipvs.ko
-rw-r--r-- 1 root root   8168 Feb 29 18:10 xt_LED.ko
-rw-r--r-- 1 root root   4456 Feb 29 18:10 xt_length.ko
-rw-r--r-- 1 root root   6480 Feb 29 18:10 xt_limit.ko
-rw-r--r-- 1 root root   4200 Feb 29 18:10 xt_mac.ko
-rw-r--r-- 1 root root   4936 Feb 29 18:10 xt_mark.ko
-rw-r--r-- 1 root root   5144 Feb 29 18:10 xt_multiport.ko
-rw-r--r-- 1 root root   4536 Feb 29 18:10 xt_NFLOG.ko
-rw-r--r-- 1 root root   6080 Feb 29 18:10 xt_NFQUEUE.ko
-rw-r--r-- 1 root root   4792 Feb 29 18:10 xt_NOTRACK.ko
-rw-r--r-- 1 root root   9536 Feb 29 18:10 xt_osf.ko
-rw-r--r-- 1 root root   4272 Feb 29 18:10 xt_owner.ko
-rw-r--r-- 1 root root   5192 Feb 29 18:10 xt_physdev.ko
-rw-r--r-- 1 root root   4224 Feb 29 18:10 xt_pkttype.ko
-rw-r--r-- 1 root root   5896 Feb 29 18:10 xt_policy.ko
-rw-r--r-- 1 root root   5120 Feb 29 18:10 xt_quota.ko
-rw-r--r-- 1 root root   5960 Feb 29 18:10 xt_rateest.ko
-rw-r--r-- 1 root root   8968 Feb 29 18:10 xt_RATEEST.ko
-rw-r--r-- 1 root root   4072 Feb 29 18:10 xt_realm.ko
-rw-r--r-- 1 root root  20136 Feb 29 18:10 xt_recent.ko
-rw-r--r-- 1 root root   5432 Feb 29 18:10 xt_sctp.ko
-rw-r--r-- 1 root root   6856 Feb 29 18:10 xt_SECMARK.ko
-rw-r--r-- 1 root root  10432 Feb 29 18:10 xt_set.ko
-rw-r--r-- 1 root root   8704 Feb 29 18:10 xt_socket.ko
-rw-r--r-- 1 root root   5056 Feb 29 18:10 xt_state.ko
-rw-r--r-- 1 root root   5232 Feb 29 18:10 xt_statistic.ko
-rw-r--r-- 1 root root   5088 Feb 29 18:10 xt_string.ko
-rw-r--r-- 1 root root   5024 Feb 29 18:10 xt_tcpmss.ko
-rw-r--r-- 1 root root   8496 Feb 29 18:10 xt_TCPMSS.ko
-rw-r--r-- 1 root root   5616 Feb 29 18:10 xt_TCPOPTSTRIP.ko
-rw-r--r-- 1 root root   6376 Feb 29 18:10 xt_tcpudp.ko
-rw-r--r-- 1 root root   9216 Feb 29 18:10 xt_TEE.ko
-rw-r--r-- 1 root root   6024 Feb 29 18:10 xt_time.ko
-rw-r--r-- 1 root root  10848 Feb 29 18:10 xt_TPROXY.ko
-rw-r--r-- 1 root root   4184 Feb 29 18:10 xt_TRACE.ko
-rw-r--r-- 1 root root   5176 Feb 29 18:10 xt_u32.ko

O kernel atual é o 3.2.0-4-amd64 no sistema Debian Wheezy

[email protected] # uname -r
3.2.0-4-amd64
[email protected] # lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 7.9 (wheezy)
Release:    7.9
Codename:   wheezy

Vou tentar instalar o kernel wheezy-backports, 3.16.0-0.bpo.4-amd64.

ATUALIZAÇÃO 5

Eu poderia carregar os módulos corretos após inicializar o kernel wheezy-backports 3.16.0-0.bpo.4-amd64

[email protected] # uname -r
3.16.0-0.bpo.4-amd64

[email protected] # modprobe -v iptable_nat
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/x_tables.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/nf_conntrack.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/nf_nat.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/ip_tables.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/iptable_nat.ko

[email protected] # lsmod |grep nat
iptable_nat            12646  1 
ip_tables              25967  2 iptable_filter,iptable_nat
nf_nat_ipv4            12912  1 iptable_nat
nf_nat                 18159  3 ipt_MASQUERADE,nf_nat_ipv4,iptable_nat
nf_conntrack           91426  6 ipt_MASQUERADE,nf_nat,xt_state,nf_nat_ipv4,iptable_nat,nf_conntrack_ipv4
    
por Markus Lindberg 30.03.2016 / 10:24

1 resposta

0

Portanto, parece que a instalação do Debian Wheezy tinha um kernel defeituoso ou o NAT não era totalmente suportado por ele. Estava faltando um módulo específico do kernel, nf_nat_ipv4 . Como pode ser visto aqui:

[email protected] # lsmod |grep nat
iptable_nat            12928  1 
nf_nat                 18231  2 iptable_nat,ipt_MASQUERADE
nf_conntrack_ipv4      14078  3 nf_nat,iptable_nat
nf_conntrack           52720  5 nf_conntrack_ipv4,nf_nat,iptable_nat,ipt_MASQUERADE,xt_state
ip_tables              22042  2 iptable_nat,iptable_filter
x_tables               19118  6 ip_tables,iptable_nat,ipt_MASQUERADE,iptable_filter,xt_state,ipt_LOG

Instalar o kernel 3.16.0-0.bpo.4-amd64

O kernel padrão para o Debian Wheezy é 3.2.0-4-amd64 . Então, instalei o kernel wheezy-backports 3.16.0-0.bpo.4-amd64 .

[email protected] # apt-get update
[email protected] # apt-get install linux-image-3.16.0-0.bpo.4-amd64 linux-headers-3.16.0-0.bpo.4-all-amd64

The following packages have unmet dependencies:
 linux-image-3.16.0-0.bpo.4-amd64 : Depends: initramfs-tools (>= 0.110~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

O APT reclamou que o pacote initramfs-tools correto não pôde ser instalado como uma dependência. Então eu tenho que instalar isso do punho wheezy-backports:

[email protected] # apt-get -t wheezy-backports install initramfs-tools

Eu poderia então instalar o 3.16.0-0.bpo.4-amd64 kernel:

[email protected] # apt-get install linux-image-3.16.0-0.bpo.4-amd64 linux-headers-3.16.0-0.bpo.4-all-amd64

Eu reinicio o sistema e continuo carregando os moduels do kernel NAT.

Carregando os módulos do kernel NAT

Eu verifiquei primeiro se carreguei o kernel correto:

[email protected] # uname -r
3.16.0-0.bpo.4-amd64

O sistema está atualmente executando o kernel backports. Eu prossegui com o carregamento nos módulos do kernel NAT:

[email protected] # modprobe -v iptable_nat
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/x_tables.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/nf_conntrack.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/netfilter/nf_nat.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/ip_tables.ko 
insmod /lib/modules/3.16.0-0.bpo.4-amd64/kernel/net/ipv4/netfilter/iptable_nat.ko

[email protected] # lsmod |grep nat
iptable_nat            12646  1 
ip_tables              25967  2 iptable_filter,iptable_nat
nf_nat_ipv4            12912  1 iptable_nat
nf_nat                 18159  3 ipt_MASQUERADE,nf_nat_ipv4,iptable_nat
nf_conntrack           91426  6 ipt_MASQUERADE,nf_nat,xt_state,nf_nat_ipv4,iptable_nat,nf_conntrack_ipv4

Testando NAT

Em seguida, configurei o encaminhamento de ip e o NAT novamente, pois ele desaparecia após a inicialização:

[email protected] # echo 1 > /proc/sys/net/ipv4/ip_forward
[email protected] # iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

Então eu testei para ping de 192.168.0.236 e funcionou:

[email protected] # ping 10.93.89.1
10.93.89.1 is alive!

Conclusões

O problema era que os módulos corretos do kernel NAT não podiam ser carregados e para corrigir isso eu tive que instalar o kernel do wheezy-backports e carregar os módulos do kernel NAT.

    
por 01.04.2016 / 16:07