Linux configure web server port on linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am running Play Framework on Linux and at the moment the URL is
http://www.example.net:9999
How do I change it to
http://www.example.net
I also want to run a ssh port
http://www.example.net:9443
Is this a linux configuration or is it on the web server?
If its linux any relevant links would be helpful.
UPDATE
Following biesiors answer below I realised that by default if you set the port to 443 for ssh then you automatically get the url
https://www.example.net
which is equivalent to
https://www.example.net:443
This however still didn't work on my ec2 instance. Following some investigation and trial and error I found that if I started my web server with root then this port was available and worked. So now I just need to figure out the permissions.
So the answer is
You need to be root (superuser) to bind to ports under 1024. That's why 9443 works, but 443 doesn't
So my question still stands at how do I run with port 9443 but have the url below and is it ok to run the webserver as root, it doesn't seem right
https://www.example.net
EDIT 2:
So the answer is that you need to remap the ports in the the IP tables
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 9000
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 9443

Although your question is very wide... I just guess you have two possible solution:
Start your application using port 80 - if it's available
If you have some common web server working on port 80 (and want to keep it) you need to configure it to work as a front-end HTTP server as described in the docs

In order to use the port 9443 instead of the default ssl port 443 for which you need to be a root or super user you will need to remap the ports in the iptables
For playframework the default port is 9000 and not 80 or 8080 so you need to remap that
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 9000
For the ssl port you need to map from 443 to 9443 so
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 9443

Related

iptables how to specify port forwarding for only a few IPs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I inherited a complex iptables script acting as our gateway/router. It handles everything well, including NAT and harpin nat. It also does port forwarding. However, the port forwarding can't be specified by source IP. So if the port 25 is forwarded, every IP can connect to that port.
The FORWARD chain policy is ACCEPT. I tried to change it to DROP and built some rules. It seems that there are too much on specifying rules for every allow scenario.
What I am looking for is to specify things like this:
iptables -A FORWARD -p tcp -i $WAN_IFACE --dport 25 -s (!(1.1.1.1 and
1.1.1.2)) -j DROP
But iptables does not support and and or.
Is there any way to implement this?
You can create a new chain for all packets going to Port 25 and then do more specific filtering there:
iptables -N port25
iptables -A FORWARD -p tcp -i $WAN_IFACE --dport 25 -j port25
iptables -A port25 -s 1.1.1.1 -j ACCEPT
iptables -A port25 -s 1.1.1.2 -j ACCEPT
iptables -A port25 -j DROP
The creation of user-defined chains is the way to implement and and or rules.

linux iptables redirect outgoing traffic to local port [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I want redirect all outgoing traffic with port 8080 to local port 8080
for example i create server with this command nc -l -p 8080 and i want when use this command nc 1.2.3.4 8080 , nc redirect and connect to 127.0.0.1:8080
i try with this command:
iptables -t nat -A POSTROUTING -p tcp --dport 80 -o eth0 -j SNAT --to-source IP
but not worked!
how to do it?
Local originated traffic isn't passing through nat/POSTROUTING chain. You should add rule like this:
iptables -t nat -A OUTPUT -p tcp --dport 8080 -j DNAT --to-destination 127.0.0.1:8080
Additional info:
http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg
http://www.linuxtopia.org/Linux_Firewall_iptables/index.html Chapter 4.

Open port 443 by adding a rule in iptables (Ubuntu) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Im new to ubuntu and using ubuntu server 12.04.
When I run nmap localhost I get the following output :
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
This means that port 443(https) is closed. I want to open it.
So I did the following :
I ran the command
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
And to persist the changes I saved the file using sudo sh -c "iptables-save > /etc/iptables.rules"
and then I added the following lines to etc/network/interfaces :
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
After rebooting my system I ran sudo iptables -L and the line
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:https
was visible.
However now when I run nmap localhost I still dont see 443 as open.
Please help!
I bet you have nothing listening to port 443 on your host. Try this: in one terminal run sudo nc -lk 443 and then run your nmap localhost. This may not have anything to do with an iptables firewall rule.

iptables to drop input connections to postgres [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
For testing, I need to drop all input connections to postgres db running on port 5432 on localhost. I set an iptables rule :
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 5432 -j DROP
But I am able to do read/write operations to the db. I used dbvisualizer as well as the product to test. What am I missing?
Thanks in advance.
The target DROP will just drop the packet, no further processing or forwarding.
try this:
iptables -t nat -A PREROUTING -p tcp -j REDIRECT --to-ports 5432
I am not sure if this is the right method but rule
iptables -A OUTPUT -p tcp --dport 5432 -j REJECT
worked as expected.
Did your server listen on localhost or ethernet nic network ip address?

iptables to forward port to another network [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a VDS running CentOS with two interfaces: eth0 and ham0. eth0 is my WAN interface and has external IP accessible from the Internet, and ham0 is an interface to a small VPN network (Logmein Hamachi).
There are three machines in the VPN network, one of them is a linux box at my home which runs Apache on port 80. This machine is behind ISP's NAT and cannot be seen from outside.
I want to create a rule on my VDS to forward connections to port 8081 coming from the Internet (eth0 interface) to this linux box inside my VPN network. Something like this:
[Internet] ---> [VDS server with public IP] ---> [Apache server inside VPN]
I used the following rules:
iptables -t nat -A PREROUTING -p tcp -d *external_ip* --dport 8081 -j DNAT --to *internal_ip*:80
iptables -A FORWARD -p tcp -d *internal_ip* --dport 80 -j ACCEPT
iptables -t nat -A POSTROUTING -p tcp --dst *internal_ip* -j LOG --log-level warning --log-prefix "[REQUEST_FORWARDED]"
But it does not work. I can see a "REQUEST_FORWARDED" message in /var/log/messages, but when I go to the http://my_eternal_ip:8081/ in my browser, it tries to connect to the host for a very long time, and then shows a message that server did not respond.
What can cause this problem?
I guess you need to make sure "/proc/sys/net/ipv4/ip_forward" has been enabled, if not
echo 1 > /proc/sys/net/ipv4/ip_forward
Above command can help you allow IP forwarding.
Hope this helpful to you.

Resources