Koozali.org: home of the SME Server

Portforwarding not working after fresh install & updates

pwinkler

Portforwarding not working after fresh install & updates
« on: November 11, 2004, 01:45:03 AM »
i am trying to forward port 3389 (terminal services) to a server behind sme server and it is not working.

I have this working on two other servers on the same site but this one does not want to work.

As mentiond above this is a fresh install with updates applied.

What do I look for?

Pls help

guest22

Portforwarding not working after fresh install & updates
« Reply #1 on: November 11, 2004, 06:04:50 AM »
Hi,

Which version, what updates?

RequestedDeletion

pwinkler

Portforwarding not working after fresh install & updates
« Reply #2 on: November 11, 2004, 05:09:15 PM »
SME 6.0.1-01 and the updates from the update script
on this thread

http://forums.contribs.org/index.php?topic=24285.0

guest22

Portforwarding not working after fresh install & updates
« Reply #3 on: November 11, 2004, 05:26:45 PM »
Hi Pwinkler,

Please keep in mind that the updatescript is not an 'official' contribs. Next to that I do not see anything within the mentioned script that could harm the default portfowarding functionality.

I personally portforward 3389 on some setups with SME Server 6.0.1-01 with no problems. Did you sniff already to see if the port is indeed forwarded?

RequestedDeletion

pwinkler

Portforwarding not working after fresh install & updates
« Reply #4 on: November 11, 2004, 05:57:58 PM »
What updates are "contribs" or what should i install after a basic install?

I have tried to telnet to the ip on port 3389 and get
"could not open a connection to host.. connect failed"

guest22

Portforwarding not working after fresh install & updates
« Reply #5 on: November 11, 2004, 06:48:50 PM »
Take a look at '/etc/init.d/masq' and look for 3389. If it's in there then SME Server is doing it's job ;-)

RequestedDeletion

pwinkler

Portforwarding not working after fresh install & updates
« Reply #6 on: November 11, 2004, 07:55:38 PM »
there is no "3389" in /etc/rc.d/init.d/masq

guest22

Portforwarding not working after fresh install & updates
« Reply #7 on: November 11, 2004, 10:47:18 PM »
Then what you describe is correct ;-)

How did you try to port forward? If it is via the server manager (default) then remove and add again just to see what happens.

Any chance you have a custom template/fragment regarding masq?

btw: joining IRC on freenode # sme-server would get you to 'live' people :-)

guest

pwinkler

Portforwarding not working after fresh install & updates
« Reply #8 on: November 12, 2004, 01:10:03 AM »
I have already deleted & re-entered the portforwarding using the panel a couple of times and again just now, I also checked /etc/init.d/masq again to see if there was any change but no!

guest22

Portforwarding not working after fresh install & updates
« Reply #9 on: November 12, 2004, 08:37:07 AM »
Ok, time to get it working first and then find out what's wrong ;-)

Create a custom template by copying /etc/e-smith/templates/etc/rc.d/init.d/91AdjustPortForward

to /etc/e-smith/custom-templates/etc/rc.d/init.d/91AdjustPortForward
/etc

then edit the custom template fragment by adding the below rule:

# Start portforwarding rule port 3389 MS-TS
--destination-port 3389 -j DNAT --to-destination 192.168.5.3:3389
adjust_tcp_in 3389 ACCEPT ForwardedTCP_$$ 192.168.5.3/32
# End portforwatding rule

so the section looks like:
# Create a new PortForwarding chain
PFC=$(/sbin/iptables --table nat --numeric --list PortForwarding |\
   sed -n '3s/ .*//p')
    /sbin/iptables --table nat --new-chain PortForwarding_$$
    /sbin/iptables --table nat --append PortForwarding_$$ --protocol tcp \
         --destination-port 3389 -j DNAT --to-destination 192.168.5.3:3389
    adjust_tcp_in 3389 ACCEPT ForwardedTCP_$$ 192.168.5.3/32
    /sbin/iptables --table nat --replace PortForwarding 1 --destination $OUTERNET --jump PortForwarding_$$
    /sbin/iptables --table nat --flush $PFC
    /sbin/iptables --table nat --delete-chain $PFC

where 192.168.5.3 is the IP address of the accepting machine.

Expand the new template fragment and restart masq

Portforwarding 3389 should now work.

RequestedDeletion

pwinkler

Portforwarding not working after fresh install & updates
« Reply #10 on: November 12, 2004, 01:20:27 PM »
Thanks for your help thus far RequestedDeletion.

I tried copying
/etc/e-smith/templates/etc/rc.d/init.d/masq/91AdjustPortForward

to
 
/etc/e-smith/custom-templates/etc/rc.d/init.d/91AdjustPortForward
/etc

Mybe I'm a bit thick but I can't find the second path path or anything like it!

Do you want me to create it?

Anyway, I have copied & edited the  template as per your instructions.

Thanks again!

guest22

Portforwarding not working after fresh install & updates
« Reply #11 on: November 12, 2004, 01:27:06 PM »
Yep, you need to create the path: /etc/e-smith/custom-templates/etc/rc.d/init.d/

RequestedDeletion

Offline compdoc

  • ****
  • 211
  • +0/-0
Portforwarding not working after fresh install & updates
« Reply #12 on: November 15, 2004, 04:05:28 AM »
you sure youre forwarding to the right internal IP address? And that the hardware is right? I've never seen port forwarding fail in any release of SME - even when you had to install your own server panel.

Offline rmoria

  • ***
  • 78
  • +0/-0
    • http://www.osvorca.nl
Portforwarding not working after fresh install & updates
« Reply #13 on: November 22, 2004, 02:47:01 AM »
Same problem here.

Fresh install of 6-01-01. I did not use the install-script, but I did use a lot of the same contribs.

Trying to change the template did not help (or work) up till now.
I have to change a lot more ports (not just 3389).

Is there somewhere else we can look.
...
Yes, I can ask more questions then you can answer  8-)
...

guest22

Portforwarding not working after fresh install & updates
« Reply #14 on: November 22, 2004, 10:44:40 AM »
Hi,

Well I guess it's time to check te contribs used. A fresh install of SME Server 6.0.1-01 works perfectly. Maybe you guys can team up and find out what contributions you have in common?

RequestedDeletion

Offline rmoria

  • ***
  • 78
  • +0/-0
    • http://www.osvorca.nl
Portforwarding not working after fresh install & updates
« Reply #15 on: November 22, 2004, 10:56:49 AM »
I installed:

scripted:
Antivirus (latest by Knuddi)
Spamassasin (latest by Knuddi)
Dshield
php4.3.8-upgrade
webshare
dhcpconfig V0.3.3beta(suspect ?)

RPM:
awstats
backup2ws
crontab manager
lazyadmin tools
navmanager
netPBM
Samba 3.0
Sarg
Sysmon
Userpanel
Winupd
updates (al in directory from Knuddi)

Rob
(not trained enough to figure it out by himself)
...
Yes, I can ask more questions then you can answer  8-)
...

pwinkler

Portforwarding not working after fresh install & updates
« Reply #16 on: November 22, 2004, 10:10:37 PM »
I used the update script (http://forums.contribs.org/index.php?topic=24285.0) so all the contribs in that script and the only other contribs were the services panel & isoqlog

Offline rmoria

  • ***
  • 78
  • +0/-0
    • http://www.osvorca.nl
Portforwarding not working after fresh install & updates
« Reply #17 on: November 22, 2004, 11:50:57 PM »
Not having any patiance, I started a new installation to see if the problem lies with one of the installed contribs.

After a fresh install and restore (originaly made on a SME 6beta3) port forwarding is not already not working.
Same with remote access settings.
No contribs are installed.
...
Yes, I can ask more questions then you can answer  8-)
...

Offline rmoria

  • ***
  • 78
  • +0/-0
    • http://www.osvorca.nl
Portforwarding not working after fresh install & updates
« Reply #18 on: November 23, 2004, 10:02:40 AM »
Yes!
My problem lay in the backup / restore action. After removing all custom templates and practacly all files in the /home/e-smith directory (config files) from the backup gz/tar it works fine, even with all contribs.

I just have to setup all settings again  :cry:  but at least I can.
...
Yes, I can ask more questions then you can answer  8-)
...

Nicky

Clean Solution for UDP PortForwarding Bug
« Reply #19 on: May 20, 2006, 12:06:01 AM »
Replace /etc/e-smith/templates/etc/rc.d/init.d/masq/91ajustPortForward with this:

# ------------------------ cut here ----------------------------------------
#
# Corrected UDP PortForwarding Bug! (by Néstor D. Díaz - nestorddiaz@matelogic.com.ar)
#

{
my $pf_chain = "PortForwarding_\$\$";
$OUT .= "# Create a new PortForwarding chain\n";
$OUT .= "PFC=\$(/sbin/iptables --table nat ";
$OUT .= "--numeric --list PortForwarding |\\\n";
$OUT .= " sed -n '3s/ .*//p')\n";
$OUT .= " /sbin/iptables --table nat --new-chain $pf_chain\n";

foreach my $protocol (qw(tcp udp))
{
my $uproto = uc $protocol;
my $propname = $uproto . "Forwards";
my %forwards = split(/,/, $masq{$propname} || '');
foreach my $port (keys %forwards)
{
my ($ip, $dport) = split(/:/, $forwards{$port});
$port =~ s/-/:/;
$OUT .= " /sbin/iptables --table nat --append $pf_chain " .
"--protocol $protocol \\\n".
# Set up local port to forward
" --destination-port ${port} -j DNAT " .
# Set up the remote port to forward to
"--to-destination $ip";
# Append the dport if any.
$OUT .= ":$dport" if $dport;
$OUT .= "\n";
# And accept the incoming packets. Use the dport if there is one.
($port = $dport) =~ s/-/:/ if $dport;
# If this rule is forwarding to localhost, ExternalIP or LocalIP,
# then we must allow it on the INPUT chain instead of the FORWARD
# chain.
if (($ip eq '127.0.0.1') ||
($ip eq $InternalInterface{IPAddress}))
{
# Bad doggie! Bad!
die "Port-forwarding to localhost or internal interface not permitted.\n";
}
elsif ($ip eq $ExternalInterface{IPAddress})
{
if ($uproto eq 'tcp')
{
$OUT .= " adjust_tcp_in $port ACCEPT Inbound${uproto}_\$\$\n";
}
else
{
$OUT .= " adjust_udp_in $port ACCEPT Inbound${uproto}_\$\$\n";
}
}
else
{
if ($uproto eq 'tcp')
{
$OUT .= " adjust_tcp_in $port ACCEPT Forwarded${uproto}_\$\$ $ip/32\n";
}
else
{
$OUT .= " adjust_udp_in $port ACCEPT Forwarded${uproto}_\$\$ $ip/32\n";
}
}
}
}

# having created a new PortForwarding chain, activate it and destroy
# the old.
$OUT .= " /sbin/iptables --table nat --replace PortForwarding 1 " .
"--destination \$OUTERNET --jump $pf_chain\n";
$OUT .= " /sbin/iptables --table nat --flush \$PFC\n";
$OUT .= " /sbin/iptables --table nat --delete-chain \$PFC\n";
}
# ------------------------ cut here ----------------------------------------

Or Download this file from:
http://www.matelogic.com.ar/91adjustPortForward

Cheers!

Nicky

Correction!!!
« Reply #20 on: May 20, 2006, 03:57:43 AM »
Sorry!!!

Where "if ($uproto eq 'tcp')" must say "if ($protocol eq 'tcp')".

Download from here:
http://www.matelogic.com.ar/91adjustPortForward

Nicky

Example of the Bug
« Reply #21 on: May 20, 2006, 04:46:52 PM »
Example of the Bug:
-----------------------

Some IPTables Rules:

Chain ForwardedTCP (1 references)
target prot opt source destination
ForwardedTCP_24182 all -- anywhere anywhere
denylog tcp -- anywhere anywhere tcp flags:SYN,RST,ACK/SYN

Chain ForwardedTCP_24182 (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere pc-00007.matelogic.com.artcp dpt:4890
ACCEPT tcp -- anywhere pc-00069.matelogic.com.artcp dpt:4357
ACCEPT tcp -- anywhere pc-00007.matelogic.com.artcp dpt:4500
ACCEPT tcp -- anywhere pc-00069.matelogic.com.artcp dpt:4889

Chain ForwardedUDP (1 references)
target prot opt source destination
ForwardedUDP_24182 all -- anywhere anywhere
denylog udp -- anywhere anywhere

Chain ForwardedUDP_24182 (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere pc-00007.matelogic.com.arudp dpt:6430
ACCEPT tcp -- anywhere pc-00009.matelogic.com.arudp dpt:27015
ACCEPT tcp -- anywhere pc-00069.matelogic.com.arudp dpt:6474

Comment: The last 3 lines must be "udp" protocol.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Portforwarding not working after fresh install & updates
« Reply #22 on: May 22, 2006, 12:05:46 AM »
Quote from: "guest22"
Ok, time to get it working first and then find out what's wrong ;-)


Quite the wrong thing to do. Find out what's wrong, then fix it.

Here's the ultimate recipe:

Step 1 - apply all updates
Step 2 - if there's still a malfunction, report via the Bug Tracker