Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Новый участник


Сообщения: 32
Благодарности: 0

Профиль | Отправить PM | Цитировать


У меня как раз проблема подобного рода, но порт надо прокидывать из одной подсети (192.168.1.0/24) в другую (192.168.0.0/24).

Почитал вот это: http://www.opennet.ru/base/net/dnat_linux.txt.html
И решил написать простенький скриптик для удобства:
Код: Выделить весь код
#!/bin/sh

#IP внутренней сети, передаётся первым параметром
INT_IP=$1

#IP внешней сети
EXT_IP="192.168.0.1"

INT_PORT=$2
EXT_PORT=$3

#интерфейс, который смотрит во внутреннюю подсеть
INT_IF="br0"

#Это может пригодиться потом 
#EXT_IF="vlan1"

iptables -t nat -A  PREROUTING -p tcp -d $EXT_IP --dport $EXT_PORT -j DNAT --to-destination $INT_IP:$INT_PORT
iptables -A FORWARD -i $INT_IF -d $INT_IP -p tcp --dport $INT_PORT -j ACCEPT
Теперь по идее, запустив этот скрипт с параметрами, скажем
./portout 192.168.1.4 80 80
мы должны обращаясь на 192.168.0.1:80 получить доступ на 80-й порт машины 192.168.1.4, но этого почему-то не происходит.

Код: Выделить весь код
[admin@router scripts]$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

[admin@router scripts]$ iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
VSERVER    all  --  anywhere             192.168.0.1

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain VSERVER (1 references)
target     prot opt source               destination

[admin@router scripts]$ cat /etc/hosts | grep book
192.168.1.4 book

[admin@router scripts]$ ./portout.sh 192.168.1.4 80 80

[admin@router scripts]$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             book               tcp dpt:www

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

[admin@router scripts]$ iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
VSERVER    all  --  anywhere             192.168.0.1
DNAT       tcp  --  anywhere             192.168.0.1        tcp dpt:www to:192.168.1.4:80

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain VSERVER (1 references)
target     prot opt source               destination
Подскажите пожалуйста, что же я делаю не так?

Отправлено: 06:01, 20-09-2007 | #5