LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-12-2017, 08:17 PM   #1
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Rep: Reputation: 15
How do I redirect an incoming non standard port?


Being that my ISP blocks ports 80 and 443, (mainly because they say if I'm running a server on those ports, then I'm running a business and need to buy a business account), but instead I use non-standard ports above 10000, IE,,, HTTP = 12080, HTTPS = 12443, and then use noip.com to perform a web redirect, so that my dynamic host name (http://my-name.no-ip.xxx) is then redirected to (http://IP:port), and all my web sites running on my home server using apache are configured to use those non standard ports.

Now, here's the dilemma, is it possible to create a virtual host (name based) in apache that would listen on port 80 for HTTP, but being that my ISP blocks port 80, and I use port 12080 externally, any HTTP requests would first come in on port 12080, then get redirected to the virtual host on port 80.

EG,

someone outside my LAN, types into their browser http://my-host.no-ip.xx which is redirected via noip.com to http://IP:12080 my router is configured to allow incoming on port 12080 to my server LAN IP.

The idea now, is for that HTTP request on port 12080 to be intercepted on the sever side, and then gets redirected to port 80, where the virtual host is listening, that way I can use scripts that are hard-coded to use port 80. One such application is Owncloud, I can't use the updater, because even though the rest of the scripts works fine when using a non-standard port, the updater is hard-coded to run on port 80, which is unreachable on the WAN, and therefore fails the updates.

Last edited by Usalabs; 05-12-2017 at 08:21 PM.
 
Old 05-12-2017, 11:14 PM   #2
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
If your IP does not change too often or at all, you could maybe use something like cloudflare? I'm not 100% sure though. Another way might be a VPN that supports listener ports. Essentially you connect to the VPN provider and through it you can forward ports. People would be connecting to you through the VPN but it would be rather transparent. If you get a VPS host you could DIY too. That's what I would do as you get more control.

I hate the fact that ISPs don't allow servers too, I think that whole thing is BS. I have fibre to the home and a decent home server infrastructure, I'd love to be able to run my stuff at home too without having to use any kind of hack.

I ended up just getting a good deal on a dedicated server at OVH and host all my web stuff there. One thing that's crossed my mind though is to do some kind of iSCSI over a SSH or VPN tunnel. Would allow to expand the disk space on the online server without having to pay extra per month. The latency on something like that would probably be pretty brutal though. :P
 
Old 05-12-2017, 11:29 PM   #3
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Red Squirrel View Post
If your IP does not change too often or at all, you could maybe use something like cloudflare? I'm not 100% sure though. Another way might be a VPN that supports listener ports. Essentially you connect to the VPN provider and through it you can forward ports. People would be connecting to you through the VPN but it would be rather transparent. If you get a VPS host you could DIY too. That's what I would do as you get more control.

I hate the fact that ISPs don't allow servers too, I think that whole thing is BS. I have fibre to the home and a decent home server infrastructure, I'd love to be able to run my stuff at home too without having to use any kind of hack.

I ended up just getting a good deal on a dedicated server at OVH and host all my web stuff there. One thing that's crossed my mind though is to do some kind of iSCSI over a SSH or VPN tunnel. Would allow to expand the disk space on the online server without having to pay extra per month. The latency on something like that would probably be pretty brutal though. :P
I looked at a few VPN's and they are either scams or just plain too expensive, I already pay a lot for my 30Mb/s download and 17Mb/s upload speed, I don't want get way into 3 figures.

I haven't delved into how Squid works, but would something like squid (a proxy) do something like listen on one port and redirect to another?
 
Old 05-13-2017, 03:27 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Usalabs View Post
The idea now, is for that HTTP request on port 12080 to be intercepted on the sever side, and then gets redirected to port 80, where the virtual host is listening, that way I can use scripts that are hard-coded to use port 80.
by "server" i guess you mean your server, i.e. your machine.
this would work on my router, which has settings for port forwarding.
so on my local network apache listens to port 80, but the router forwards traffic from the outside from port 12080 to port 80 internally, no problem.
if your router cannot do that you can either hack your router or find some software solution that does the same (i'm sure sth liek that exists for linux).
 
Old 05-13-2017, 10:49 AM   #5
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ondoho View Post
by "server" i guess you mean your server, i.e. your machine.
this would work on my router, which has settings for port forwarding.
so on my local network apache listens to port 80, but the router forwards traffic from the outside from port 12080 to port 80 internally, no problem.
if your router cannot do that you can either hack your router or find some software solution that does the same (i'm sure sth liek that exists for linux).
Yes my home server.

My router does have port forwarding, but it's very basic, it's just forward what port to what LAN IP, I already have port 12080 forwarded to my LAN server IP:-

Service Name:- HTTP
Service Type:- Both
Starting Port:- 12080
Ending Port:- 12080
Server IP:- 192.168.xxx.xxx

This configuration has to assume that Apache is listening on port 12080 for the router to direct HTTP request to that port.

to forward a port in my router these are the only options:-

Service Name:- ___________
Service Type:- ----> Drop down selection UDP, TCP Both
Starting Port:- __________
Ending Port:- __________
Server IP:- __________

Starting and Ending ports would be inclusive as a range of ports, such as Starting:- 1000, Ending:- 1100 would open port range 1000-1100

There's no actual port redirection from within the router itself, it would have to be done on the server running Apache.

The software would have to listen on port 12080 for an HTTP request then direct that request to port 80 where Apache is listening.
 
Old 05-13-2017, 09:14 PM   #6
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
Some years back I used a service called rinetd which to me was simpler to set up than messing with iptables. I took a look, rinetd is still available in Fedora 25 repos. rinetd does the port translation at the server.
 
Old 05-13-2017, 10:19 PM   #7
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Doug G View Post
Some years back I used a service called rinetd which to me was simpler to set up than messing with iptables. I took a look, rinetd is still available in Fedora 25 repos. rinetd does the port translation at the server.
rinetd is just what I was looking for, it's a small footprint, and the config file is easy to understand, and it's still available for OpenSuSe, and according to details, it can redirect one IP:port to another IP:port, there's even a webmin module for configuring the rinetd.conf through a web interface, much better than remembering every location of a conf file and manually editing them, I just use webmin, and do the configuration through that.

I'm going to do some testing and if it works, I'll add rinetd to boot time execution (systemctl enable rinetd)
 
Old 05-14-2017, 01:15 AM   #8
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Well, I guess it doesn't work, no matter what I try in the rinetd.conf file, rinetd either says "rinetd: host # can not be resolved on line 1", or "rinetd: Cannot bind to address in line 1"

What I did was to create a virtual host in Apache, binding it to default port 80 on all addresses, this I can test locally using the server http://serverLANIP and the html test page shows up correctly, but if I used http://WANIP it times out because my ISP blocks incoming on port 80, so I then created a dynamic web redirect on noip.com so that the url http://myown-cloud.no-ip.ddns would get redirected to http://WANIP:12080, then I configured rinetd to redirect TCP from WANIP (source) on port 12080 to server LANIP (destination) on port 80 where the virtual host is listening, but for some reason, rinetd says "host # can not be resolved on line 1", but if I tried any other IP address for the source, including the gateway IP, rinetd spews up "Can not bind to address:port on line 1", so I guess I'll just have to keep using old versions of software because the updaters can't use port 80, either that or just give in and try to start a business just so that I can get a tax ID and pay for a business account on my ISP so that they can open port 80.
 
Old 05-14-2017, 01:47 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
clearly your config file is malformed.
did you read
Code:
man rinetd
and its siblings - maybe
Code:
man rinetd.conf
- in their entirety?

you should also post the contents of the config file for us to inspect, but only after you read the manual and made sure that you cannot solve it yourself.

aside:
i must say you are going to a huge amount of effort to placate the wants of one piece of software.
maybe looking for a more configurable alternative to that one software would be easier alround?
or maybe it CAN be configured, but you haven't read its documentation, either?
 
Old 05-14-2017, 12:47 PM   #10
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ondoho View Post
clearly your config file is malformed.
did you read
Code:
man rinetd
and its siblings - maybe
Code:
man rinetd.conf
- in their entirety?

you should also post the contents of the config file for us to inspect, but only after you read the manual and made sure that you cannot solve it yourself.

aside:
i must say you are going to a huge amount of effort to placate the wants of one piece of software.
maybe looking for a more configurable alternative to that one software would be easier alround?
or maybe it CAN be configured, but you haven't read its documentation, either?
The problem is not in configurations, the problem lies in the programmers, they always assume that web servers will ALWAYS use default port 80, so they work on that assumption, and hard code port 80 into java scripts, hence the need for port redirection.

I read everything there is about rinetd, and the configuration is simple, just one line at a time containing:-


sourceIP Port destinationIP port

and that's it, nothing else except for logging and ACL's, the first line is always sourceIP port destinationIP port, and the default ACL is always allow, so just the one line is sufficient for testing purposes.

I have tried all combinations of these entries (1 at a time though) as the first line in rinetd.conf:-

/etc/rinetd.conf

WANIP 12080 192.168.0.100 80
192.168.0.100 12080 192.168.0.100 80
GatewayIP 12080 192.168.0.100 80
localhost 12080 192.168.0.100 80
127.0.0.1 12080 192.168.0.100 80

(192.168.0.100 is the server's static LAN IP)

all entries result in either "rinetd: host # can not be resolved on line 1" or "rinetd: can not bind to address on line 1"

According to the manual, rinetd is supposed to redirst TCP from one IP and port to another IP and port,,, sooo, in theory it should redirect TCP data from WANIP port to LANIP port, IE, WANIP 12080 -> LANIP 80, but it doesn't, and as far as I know, (unless something has changed) all HTTP TCP data from outside the LAN uses my WANIP and appears on the default port 80 unless a port is specified in the url, sooo, basically rinetd is supposed to listen on that non-standard port (12080 as used in the url, http://IP:port, or http://name:port), then redirect TCP data to the server on the LAN that is listening on a different port, ie default port 80, but as usual, Murphy's law applies (Anything that can go wrong, will go wrong) and invariably always does.

Last edited by Usalabs; 05-14-2017 at 12:49 PM.
 
Old 05-14-2017, 06:30 PM   #11
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
If it helps, here is a typical entry in rinetd.conf from when I used it. This line forwards incoming port 25112 to a LAN IP port 5900
Quote:
0.0.0.0 25112 10.0.0.112 5900 #Jeff new 3/19/2008
I haven't used rinetd in years, but I don't recall any problems with it ever. The above example was from a fedora 7 computer back then. Initially I started using rinetd because there was a version for windows server. I have numerous clients that use windows domain servers and workstations.

The error message you're referring to sounds more like you have some syntax error in your rinetd.conf file.

Last edited by Doug G; 05-14-2017 at 06:32 PM.
 
Old 05-14-2017, 07:05 PM   #12
deleted23
Member
 
Registered: Nov 2015
Distribution: Arch, Ubuntu Studio
Posts: 43

Rep: Reputation: 1
Just overflew it.
Perhaps this is what you are looking for -->


http://richardfergie.com/redirect-po...using-iptables


Greets

Last edited by deleted23; 05-14-2017 at 07:06 PM.
 
Old 05-14-2017, 11:40 PM   #13
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Doug G View Post
If it helps, here is a typical entry in rinetd.conf from when I used it. This line forwards incoming port 25112 to a LAN IP port 5900


I haven't used rinetd in years, but I don't recall any problems with it ever. The above example was from a fedora 7 computer back then. Initially I started using rinetd because there was a version for windows server. I have numerous clients that use windows domain servers and workstations.

The error message you're referring to sounds more like you have some syntax error in your rinetd.conf file.
I followed the example in the manual and I still get either one of the 2 errors, I even tried using 0.0.0.0 12080 192.168.0.100 80 and I still get the error "rinetd: can not bind to address on line 1", I'll try the other suggestion on using iptables to redirect and see if that does anything.
 
Old 05-14-2017, 11:45 PM   #14
Usalabs
Member
 
Registered: Jan 2004
Distribution: OpenSUSE 42.1 Server
Posts: 158

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bluntroller View Post
Just overflew it.
Perhaps this is what you are looking for -->


http://richardfergie.com/redirect-po...using-iptables


Greets
The example on that page shows:-

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

so I thought I could modify it a bit and try it as:-

iptables -t nat -A PREROUTING -p tcp --dport 12080 -j REDIRECT --to-port 80

which seemed to work, I can now use a web redirected DNS host name on port 12080 and I get the test html page served by Apache on port 80, even though I'm using port 12080,,, so I tried the owncloud updater and it worked,,, yay!!!!!

Thanks everyone for your help.

The problem is now solved.

Last edited by Usalabs; 05-14-2017 at 11:47 PM.
 
Old 05-15-2017, 01:18 PM   #15
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
The issue is if your ISP blocks port 80 you can do all the port redirecting you want in your internal network, you still won't be able to have something listen to port 80 on the outside. (or any port).

You could listen to port 81 and redirect to port 80 internally, but then users still have to type :81 in the url.
 
  


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
redirect all incoming ports ccc Debian 0 08-05-2014 08:44 PM
Redirect incoming traffic to an other port (ubuntu openvpn server) krisox Linux - Newbie 3 12-06-2010 12:22 AM
Redirect local DNS query to remote DNS server on non standard port? rock_ya_baby Linux - Server 8 04-13-2010 04:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:48 PM.

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