Answer redirect IP to specific port

Ahmet Can Güven

I want make a system that has a few subdomains. I set each subdomain to IP address using DNS.

I used random IP addresses for the question

165.93.198.34 x.mydomain.com (Which is actually 165.93.198.220:8080)

165.93.198.38 z.mydomain.com (Which is actually 165.93.198.220:81)

165.93.198.44 c.mydomain.com (Which is actually 165.93.198.220:443)

165.93.198.220 mydomain.com

Using iptables, when a request comes to IP address 165.93.198.34 I want it to be answered from 165.93.198.220:8080.

iptables -t nat -A PREROUTING -p tcp -d 165.93.198.34  --jump DNAT --to-destination 165.93.198.220:8080

But I couldn't make the prerouting work.

[root@static ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:down
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:webcache
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:81
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination



[root@static ~]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             165.93.198.34-iprovider.com to:165.93.198.220:8080

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

What am I doing wrong?

rda

If your target IP (165.93.198.220) is another system in the network

add an ACCEPT rule in the FORWARD chain like this:

iptables -A FORWARD -p tcp -d 165.93.198.220 --dport 8080 -j ACCEPT

also check if ip forward is enabled:

sysctl net.ipv4.ip_forward

if it is not set to 1, enable it on the fly with:

sysctl -w net.ipv4.ip_forward=1

or

echo 1 > /proc/sys/net/ipv4/ip_forward

to make it persistent for reboots edit /etc/sysctl.conf and add the line:

net.ipv4.ip_forward = 1

If your target IP (165.93.198.220) is on the local machine

add an ACCEPT rule in the INPUT chain like this:

iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Binding to a specific IP address and port to receive UDP data

VPN redirect user to specific IP and port

Binding to same port using INADDR_ANY and a specific IP simultaneously

How to redirect a domain to a different IP if accessed by a specific port?

Google load balancer redirect IP address to specific port?

Expose port of a specific container to external IP

redirect specific ip range using web.config

Redirect requests to my external IP/port to a different external IP/port?

How to allow traffic from a specific IP for a specific port in UFW?

ip6tables rules to allow port 80 and port 443 traffic to only a few specific IP addresses

configure iptables to redirect traffic to a specific IP address

Using IPtables to redirect IP address range to port range

Iptables to redirect DNS lookup IP and Port

Mod_rewrite Redirect Specific IP to page

How to setup subdomain that points to a specific port on an IP

Wget command - how to download from a specific IP address and Port

IPTables - Allow Docker port forwarding only for specific IP address

How can I kill a process running on a specific IP and port?

Allow only a specific ip address to an open port

Redirect Local DNS redirect a specific IP address

Nginx server IP on droplet redirect to specific domain

Redirect http to https exclude specific IP

How to Redirect Incoming Traffic on Port to a Diff IP and Port on macOS?

Redirect port and ip on macOS

Forward incoming request from specific ip to a local ip and port in ubuntu

How to redirect a specific user to a question answer page on login in laravel

How to reroute traffic to an ip to a specific port to display website

Redirecting page to specific IP and port in lighttpd

How to find open port on specific IP address in Windows 10?