Koozali.org: home of the SME Server

Is there a command line guide to configuring Port forwarding

Offline tolistim

  • *
  • 27
  • +0/-0
Is there a command line guide to configuring Port forwarding
« on: August 20, 2018, 09:08:21 PM »
My webmaster was mucking around with iBay settings and has botched our system to the point that we can't connect to the web server-manager interface (I'm working on that issue separately and all other services work normally).  In the mean time, I need to set up a quick port forward on the server.  Does anyone have a CLI example for setting up a port forward rule for 9.2?
Thanks,Tim
« Last Edit: August 20, 2018, 09:14:52 PM by tolistim »

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #1 on: August 20, 2018, 09:53:30 PM »
Tim

Did you try the text based server manager.
Log in as root
Then type
console
Press Enter
Then select server manager from menu.
It could be that the text based manager is also "broken".

Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline tolistim

  • *
  • 27
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #2 on: August 20, 2018, 10:06:14 PM »
Tried that first and then realized that because the text-based server-manager still depends on the web interface, it's broken both places.

Offline warren

  • *
  • 291
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #3 on: August 20, 2018, 11:15:58 PM »
Tried that first and then realized that because the text-based server-manager still depends on the web interface, it's broken both places.

1. in /home/e-smith/db for the following 2 files :

portforward_tcp
portforward_udp

if you do not have any existing rules then these files will look like :
Code: [Select]
# DO NOT MODIFY THIS FILE.
# This file is automatically maintained by the Mitel Networks SME Server
# configuration software.  Manually editing this file may put your
# system in an unknown state.
#
# updated: Thu Aug  9 19:34:43 2018

Here is what the file looks like ( i created a test port forward for tcp )

Code: [Select]
# DO NOT MODIFY THIS FILE.
# This file is automatically maintained by the Mitel Networks SME Server
# configuration software.  Manually editing this file may put your
# system in an unknown state.
#
# updated: Mon Aug 20 22:50:35 2018
26296=forward|AllowHosts|192.168.1.2|Comment|wb test|DenyHosts|0.0.0.0/0|DestHost|localhost|DestPort|26296



This is what is logged when creating the above from server-manager :

Code: [Select]
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=(undefined)
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=forward
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward|DestHost|localhost
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=forward|DestHost|localhost
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=forward|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward|Comment|wb test|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=forward|Comment|wb test|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward|AllowHosts|192.168.1.2|Comment|wb test|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: OLD 26296=forward|AllowHosts|192.168.1.2|Comment|wb test|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 /etc/e-smith/web/panels/manager/cgi-bin/portforwarding[24732]: /home/e-smith/db/portforward_tcp: NEW 26296=forward|AllowHosts|192.168.1.2|Comment|wb test|DenyHosts|0.0.0.0/0|DestHost|localhost|DestPort|26296
Aug 20 22:50:35 roxy1 esmith::event[24733]: Processing event: portforwarding-update
Aug 20 22:50:35 roxy1 esmith::event[24733]: Running event handler: /etc/e-smith/events/actions/generic_template_expand
Aug 20 22:50:35 roxy1 esmith::event[24733]: expanding /etc/rc.d/init.d/masq
Aug 20 22:50:35 roxy1 esmith::event[24733]: generic_template_expand=action|Event|portforwarding-update|Action|generic_template_expand|Start|1534798235 555086|End|1534798235 949021|Elapsed|0.393935
Aug 20 22:50:35 roxy1 esmith::event[24733]: Running event handler: /etc/e-smith/events/actions/adjust-services
Aug 20 22:50:36 roxy1 esmith::event[24733]: adjusting non-supervised masq (adjust)
Aug 20 22:50:36 roxy1 esmith::event[24733]: adjust-services=action|Event|portforwarding-update|Action|adjust-services|Start|1534798235 949473|End|1534798236 643620|Elapsed|0.694147


Might be another way ( more correct ), but i think this should work :

: create the file in /home/e-smith/db/portforward_tcp


Code: [Select]
signal-event portforwarding-update

Offline tolistim

  • *
  • 27
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #4 on: August 21, 2018, 12:22:58 AM »
That's what I was missing - the signal-event portforwarding-update
Thanks!

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #5 on: August 21, 2018, 01:04:24 AM »
Glad you got that sorted.

Not seen that before. I'll try and check if it is possible to to it entirely by CLI and add it to the wiki.

Always worth a browse through

/etc/e-smith/events

And

/etc/e-smith/events/actions

Some expect input but surprising what you can learn in there.

...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #6 on: August 21, 2018, 04:14:25 PM »
A bit more information for the future.

The server-manager sets these:

db portforward_tcp show
24444=forward
    AllowHosts=192.168.10.1
    Comment=Test
    DenyHosts=0.0.0.0/0
    DestHost=192.168.97.100
    DestPort=24444


You can manually add a port forward like this:

Code: [Select]
db portforward_tcp set {port} forward AllowHosts {some.host.ip} Comment {Test} Denyhosts {0.0.0.0/0} DestHost {dest.host.ip} DestPort {port}
Code: [Select]
db portforward_tcp set {port} forward AllowHosts {some.host.ip} Comment {Test} Denyhosts {0.0.0.0/0} DestHost {dest.host.ip} DestPort {port}
You really need a minimum of port, DestPort and DestHost

Note the following defaults unless set:

AllowHosts 0.0.0.0/0
DestPort will be set to Port if DestPort is not set

AllowHosts can be a comma separated line e.g.

AllowHosts 0.0.0.0/0,192.68.0.1

You can check the code here:

/etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward

AllowHosts/DenyHosts are also used here if set:

/etc/e-smith/templates/etc/rc.d/init.d/masq/90InboundUDP10filter_tcp
/etc/e-smith/templates/etc/rc.d/init.d/masq/90InboundUDP10filter_udp

And not forgetting:

Code: [Select]
signal-event portforwarding-update

HTH
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,722
  • +5/-0
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline tolistim

  • *
  • 27
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #8 on: August 21, 2018, 06:39:08 PM »
Thanks, ReetP. That's a great addition to the docs.

Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #9 on: August 21, 2018, 08:10:12 PM »
NP.... better late than never !!
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline warren

  • *
  • 291
  • +0/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #10 on: August 21, 2018, 10:28:30 PM »
NP.... better late than never !!

Thanks ReetP .. fixed minor spelling on wiki ( signal-event postforwarding-update ) to signal-event portforwarding-update


Offline ReetP

  • *
  • 3,722
  • +5/-0
Re: Is there a command line guide to configuring Port forwarding
« Reply #11 on: August 21, 2018, 10:40:39 PM »
Thanks :-)

Bad hair day rolling asterisk modules :lol:
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation