LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2011, 11:23 AM   #1
telsch
LQ Newbie
 
Registered: Dec 2011
Posts: 4

Rep: Reputation: Disabled
iptables forwarding ssh throw firewall


hey there,

i have a problem to find out the right configuration for iptables to forward ssh throw my firewall on a other server in local net. this server use a other gw, think thats my problem. if the firewall is my gateway no problem.

here my iptable rules, that work, if my gateway is the firewall.

Code:
iptables -A INPUT -p tcp --dport ssh -i ${WAN} -j ACCEPT

iptables -A FORWARD -p tcp -i ${WAN} -o ${LAN} --dport ssh -d ${DSERVER} -j ACCEPT
iptables -A FORWARD -p tcp -i ${LAN} -o ${WAN} --sport ssh -s ${DSERVER} -j ACCEPT
iptables -t nat -A PREROUTING --dst ${WANIP} -p tcp --dport ssh -j DNAT --to-destination ${DSERVER}
iptables -t nat -A POSTROUTING -d \! ${LOCALNET} -j SNAT --to ${WANIP}

echo 1 > /proc/sys/net/ipv4/ip_forward
for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done
 
Old 12-13-2011, 05:49 PM   #2
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
As far as I know, the firewall must be set as your gateway to use that configuration.
 
Old 12-14-2011, 03:56 AM   #3
telsch
LQ Newbie
 
Registered: Dec 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
yes i know
is it possible to say on the machine with the sshd to say if come packages from outside the lan, send them back to the firewall and dont use the gateway ??
 
Old 12-14-2011, 05:23 AM   #4
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
You can use a combination of iptables mangle table and ip route to mark the packets and route them according to the mark. Read on:

(Second example)

http://www.linuxhorizon.ro/iproute2.html

Last edited by goossen; 12-14-2011 at 05:24 AM.
 
Old 12-15-2011, 09:02 AM   #5
telsch
LQ Newbie
 
Registered: Dec 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
At moment we use this ip tables config, but on the sshd we recieve the firewall ip.

Code:
iptables -t mangle -A PREROUTING -d $WAN_IP tcp --dport ssh
iptables -t nat -A PREROUTING -j DNAT --to-destination $SSH_SERVER
iptables -t nat -A POSTROUTING -j SNAT --to-source $LAN_IP
the goal is that we see on the ssh server the ip from the client and not from the firewall. the ssh server dont have the firewall as gateway, that is the problem i have.
 
Old 03-20-2012, 06:37 AM   #6
telsch
LQ Newbie
 
Registered: Dec 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
today tried the second example from your link, goossen.

fwmark and the ip rule, this example work if go from intra to extra. but i come fom extra and want to go to intra ssh server. i think ther must be some forwarding rules and on the ssh server to ?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Port Forwarding behind university firewall metallica1973 Linux - Networking 5 09-15-2008 12:31 AM
Port Forwarding with iptables or ssh linker3000 Linux - Software 11 07-07-2008 08:41 AM
SSH port forwarding thru a NAT Firewall whoever Linux - Networking 3 07-29-2005 03:24 AM
SSH port forwarding through a firewall linuxLuser Linux - Networking 1 07-14-2005 11:29 PM
SSH tunnel or Iptables forwarding jatro Linux - Networking 5 06-15-2005 03:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration