From: Michael Shigorin <mike@osdn.org.ua> To: sysadmins@lists.altlinux.org Subject: [Sysadmins] скриптик для портфорварда на достижимый IP из альтернатив Date: Sat, 28 Mar 2009 18:45:13 +0200 Message-ID: <20090328164513.GV20208@osdn.org.ua> (raw) [-- Attachment #1: Type: text/plain, Size: 1006 bytes --] Здравствуйте. Добрался поднять дома WiFi. Работает. Теперь добрался решить порождённую этим проблему портфорварда на хост с уже двумя интерфейсами -- городить несколько портов неудобно, поскольку маршрутизирующая система более приспособлена к проверке, как бы добраться до хоста, чем человек. Поскольку ничего существующего не нагуглилось по iptables forward "same port" different addresses iptables forward "same port" multiple destination -- самое близкое: http://ubuntuforums.org/archive/index.php/t-497781.html (а спрашивавшему IMHO стоило просто делать tcp reset на tcp/113: -A INPUT -p tcp -m tcp --dport 113 -j REJECT --reject-with tcp-reset), то был нарисован прицепленный скриптик, надеюсь, достаточно самодокументированный. При необходимости его можно обобщить от двух альтернатив, но решил не усложнять без таковой. Также здесь: http://fly.osdn.org.ua/~mike/works/misc/notebook-portforward -- ---- WBR, Michael Shigorin <mike@altlinux.ru> ------ Linux.Kiev http://www.linux.kiev.ua/ [-- Attachment #2: notebook-portforward --] [-- Type: text/plain, Size: 1334 bytes --] #!/bin/sh # check which IP is reachable since the notebook can be # connected via either Ethernet or WiFi, or both; # adjust portforwarding (which must otherwise be # already set up correctly -- like not forgetting # -A INPUT -d $IP -p tcp -m tcp --dport $DPT -j ACCEPT # # try to ping an already existing portforward target; # if unreachable or none, try to ping/add another one # # (c) 2009 Michael Shigorin <mike altlinux org> # use, modify, distribute, cronjob this freely IP=EX.TER.NAL.IP # 123.45.67.8 IP_E=NOTE.BOOK.ETH.IP # 192.168.1.2 IP_W=NOTE.BOOK.WIFI.IP # 192.168.1.3 PORT=EXT_PORT # 12345 DPT=DEST_PORT # 22 COUNT=0 IFS=":" ipt() { iptables "$1" PREROUTING -t nat \ -d "$IP" -p tcp -m tcp \ --dport "$PORT" \ -j DNAT --to-destination "$2:$DPT" } remove() { ipt -D "$1"; } add() { ipt -A "$1"; } try() { ping -w1 "$1" >&/dev/null; } # is current one reachable? COUNT="`iptables -L PREROUTING -t nat -n \ | fgrep "dpt:$port" \ | ( while read header to dest rest; do try "$dest" && let COUNT=$COUNT+1 || remove "$dest" done; echo $COUNT )`" # any job left? [ "$COUNT" = 0 ] || exit for ip in "$IP_W" "$IP_E"; do try "$ip" && let COUNT=$COUNT+1 && add "$ip" && break done # any job still left? [ "$COUNT" = 0 ] || exit # safety net: add via wifi if nothing else currently possible add "$IP_W"
next reply other threads:[~2009-03-28 16:45 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-03-28 16:45 Michael Shigorin [this message] 2009-03-28 22:07 ` Michael Shigorin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090328164513.GV20208@osdn.org.ua \ --to=mike@osdn.org.ua \ --cc=shigorin@gmail.com \ --cc=sysadmins@lists.altlinux.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
ALT Linux sysadmins discussion This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/sysadmins/0 sysadmins/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 sysadmins sysadmins/ http://lore.altlinux.org/sysadmins \ sysadmins@lists.altlinux.org sysadmins@lists.altlinux.ru sysadmins@lists.altlinux.com public-inbox-index sysadmins Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.sysadmins AGPL code for this site: git clone https://public-inbox.org/public-inbox.git