Dawno tu mnie nie było - być może dlatego, że udawało mi się rozwiązywać napotkane problemy. Niedawno jednak napotkałem problem, którego nie mogę rozgryźć, ani przeskoczyć. Mianowicie chodzi o przekierowanie paru portów. Pewnie zaraz pojawią się głosy, że temat wałkowany tysiąc razy itp, a jednak problem występuje. Grzebałem już po tym forum, innych oraz przetrzepałem kieszenie wujkowi Google i nic.
Może teraz parę szczegółów. Postawiłem sobie serwer, w którym zainstalowałem qemu. Stworzyłem wirtualną maszynę poprzez qemu z serwerem www apache2. Próbuję przekierować port 80 z eth0 na port 9001 na br0. Teraz podam więcej informacji:
Kod: Zaznacz cały
ifconfig
br0       Link encap:Ethernet  HWaddr xxx 
          inet addr:10.168.10.1  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: xxx Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:964 errors:0 dropped:0 overruns:0 frame:0
          TX packets:512 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:187556 (183.1 KiB)  TX bytes:172383 (168.3 KiB)
eth0      Link encap:Ethernet  HWaddr xxx 
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: xxx Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6761 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6101 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:812145 (793.1 KiB)  TX bytes:1101365 (1.0 MiB)
          Interrupt:17 Base address:0xec00
eth1      Link encap:Ethernet  HWaddr xxx 
          inet6 addr: xxx Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:977 errors:0 dropped:0 overruns:0 frame:0
          TX packets:512 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:202696 (197.9 KiB)  TX bytes:174225 (170.1 KiB)
          Interrupt:16 Base address:0x2800
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:227 errors:0 dropped:0 overruns:0 frame:0
          TX packets:227 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:24896 (24.3 KiB)  TX bytes:24896 (24.3 KiB)
tap0      Link encap:Ethernet  HWaddr xxx 
          inet6 addr: xxx Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)Kod: Zaznacz cały
netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     *               255.255.255.0   U         0 0          0 eth0
10.168.0.0      *               255.255.0.0     U         0 0          0 br0
default         192.168.1.1     0.0.0.0         UG        0 0          0 eth0Kod: Zaznacz cały
iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request 
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ssh 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:www 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:www 
ACCEPT     tcp  --  10.168.10.0/24       anywhere            tcp dpt:domain 
ACCEPT     udp  --  10.168.10.0/24       anywhere            udp dpt:domain 
ACCEPT     udp  --  10.168.10.0/24       anywhere            udp dpt:bootps 
Chain FORWARD (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state NEW,RELATED,ESTABLISHED 
ACCEPT     tcp  --  o1                   anywhere            tcp dpt:ftp 
ACCEPT     tcp  --  o1                   anywhere            tcp dpt:www 
ACCEPT     tcp  --  o1                   anywhere            tcp dpt:7171 
ACCEPT     tcp  --  o1                   anywhere            tcp dpt:7171 
ACCEPT     icmp --  o1                   anywhere            icmp echo-request 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:9001 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:www 
Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request 
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:www 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:www 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:sshKod: Zaznacz cały
iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 422 packets, 40670 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   12   720 DNAT       tcp  --  *      *       0.0.0.0/0            192.168.1.2       tcp dpt:80 to:10.168.10.1:9001 
Chain POSTROUTING (policy ACCEPT 44 packets, 8691 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  352 24871 SNAT       all  --  *      eth0    0.0.0.0/0            0.0.0.0/0           to:192.168.1.2 
Chain OUTPUT (policy ACCEPT 325 packets, 24959 bytes)
 pkts bytes target     prot opt in     out     source               destinationKod: Zaznacz cały
#!/bin/sh
# Czyszczenie tablic NAT-a i filtrowania
iptables -F -t nat
iptables -X -t nat
iptables -F -t filter
iptables -X -t filter
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A FORWARD -o lo -j ACCEPT
iptables -A FORWARD -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED
iptables -t filter -A FORWARD -p tcp -s 10.168.10.2/32 --dport 21 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 10.168.10.2/32 --dport 80 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 10.168.10.2/32 --dport 7171 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 10.168.10.2/32 --dport 7171 -j ACCEPT
iptables -t filter -A FORWARD -s 10.168.10.2/32 -p icmp --icmp-type echo-request -j ACCEPT
iptables -t filter -A FORWARD -p tcp -i eth0 --dport 9001 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -i br0 --sport 80 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source=192.168.1.2
iptables -t nat -A PREROUTING -p tcp -d 192.168.1.2 --dport 80 -j DNAT --to-destination 10.168.10.1:9001
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED
iptables -A INPUT -s 0/0 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 0/0 -p udp --dport 22 -j ACCEPT
iptables -A INPUT -s 0/0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -s 0/0 -p udp --dport 80 -j ACCEPT
iptables -A INPUT -s 10.168.10.0/24 -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -s 10.168.10.0/24 -p udp --dport 53 -j ACCEPT
iptables -A INPUT -s 10.168.10.0/24 -p udp --dport 67 -j ACCEPT
iptables -A OUTPUT -j ACCEPT -m state --state ESTABLISHED,RELATED
iptables -A OUTPUT -s 0/0 -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -s 0/0 -p udp --dport 80 -j ACCEPT
iptables -A OUTPUT -s 0/0 -p tcp --dport 53 -j ACCEPT
iptables -A OUTPUT -s 0/0 -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -s 0/0 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -s 0/0 -p udp --dport 22 -j ACCEPTKod: Zaznacz cały
telnet 10.168.10.1 9001
Trying 10.168.10.1...
Connected to 10.168.10.1.
Escape character is '^]'.
GET /index.html
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
Connection closed by foreign host.Kod: Zaznacz cały
iptables -t nat -L -n -vKod: Zaznacz cały
12   720 DNAT       tcp  --  *      *       0.0.0.0/0            192.168.1.2       tcp dpt:80 to:10.168.10.1:9001Kod: Zaznacz cały
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j REDIRECT --to-port 9001Jeśli ktoś ma jakiś pomysł jak sprawdzić co jest nie tak lub, nawet lepiej, jak rozwiązać ten problem to czekam na propozycje.