These rules should work, assuming that iptables
is running on server 192.168.12.87
:
#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.12.77:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.12.77 --dport 80 -j SNAT --to-source 192.168.12.87
You have to DNAT incoming traffic on port 80, but you will also need to SNAT the traffic back.
Alternative (and best approach IMHO) :
Depending on what your Web Server is (Apache, NGinx) you should consider an HTTP Proxy on your front-end server (192.168.12.87) :
-
mod_proxy (Apache)
-
proxy_pass (NGinx)
Related Posts:
- How can I port forward with iptables?
- best way to clear all iptables rules
- REJECT vs DROP when using iptables
- How do I deal with a filename that starts with the hyphen (-) character?
- Bash: No such file or directory?
- What’s a .sh file?
- How can I symlink a file in Linux? [closed]
- Kill detached screen session [closed]
- How to get the url of the current svn repo?
- How to unmount a busy device
- How to unmount a busy device
- performing HTTP requests with cURL (using PROXY)
- No space left on device
- How to perform grep operation on all files in a directory?
- Amazon Linux: apt-get: command not found
- Pass a password to ssh in pure bash
- How can I exclude directories from grep -R?
- gcc: error: unrecognized command line option
- How to set proxy for wget?
- How to change permissions for a folder and its subfolders/files in one step
- Docker can’t connect to docker daemon
- Need a good hex editor for Linux
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Directory Inode vs Regular File Inode
- How to cat <
> a file containing code? - Diff command along with Grep gives “Binary file (standard input) matches”
- can’t remove python pip
- How would I get a cron job to run every 30 minutes?
- How to automatically redirect HTTP to HTTPS on Apache servers?
- Trying to use bash on Windows and got no installed distributions message
- “Unable to find remote helper for ‘https'” during git clone
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- Is there a “goto” statement in bash?
- tar: Cowardly refusing to create an empty archive
- How can I delete a user in linux when the system says its currently used in a process
- Command to change the default home directory of a user
- Post request with Wget?
- Read and write to binary files in C?
- Telnet [Unable to connect to remote host: Connection refused]
- Terminal Multiplexer for Microsoft Windows – Installers for GNU Screen or tmux
- Can’t remove a directory in Unix
- Is there an alternative sleep function in C to milliseconds?
- Gedit command not working in kali linux terminal
- Syntax error near unexpected token ‘then’
- Curl : connection refused
- How to install Android SDK on Ubuntu?
- C fopen vs open
- How can I use grep to show just filenames on Linux?
- Bash script prints “Command Not Found” on empty lines
- Why does “docker attach” hang?
- Bash export command
- How to edit gitignore file
- Retrieve last 100 lines logs
- What are various options / arguments for “./configure” in Linux
- Adding a new entry to the PATH variable in ZSH
- CronJob not running
- Delete .DS_STORE files in current folder and all subfolders from command line on Mac
- How to configure WP filesystem access in Linux (Ubuntu Server)?
- Can’t upload media to my Raspberry Pi WordPress server
- My WordPress is giving me an 403 error when saving post/draft with specific words
- Can scp copy directories recursively?
- What are the functional differences between .profile .bash_profile and .bashrc
- Why does my hostname appear with the address 127.0.1.1 rather than 127.0.0.1 in /etc/hosts?
- Linux command to inspect TXT records of a domain [closed]
- df in linux not showing correct free space after file removal
- Setting the hostname: FQDN or short name?
- When does /tmp get cleared?
- What does a + mean at the end of the permissions from ls -l?
- How do I sleep for a millisecond in bash or ksh
- What does ‘set -e’ do, and why might it be considered dangerous?
- What version of RHEL am I using?
- What useful things can one add to one’s .bashrc? [closed]
- How do you make it obvious you are on a production system?
- How to add a timestamp to bash script log?
- How can I verify if TLS 1.2 is supported on a remote web server from the RHEL/CentOS shell?
- How to remove empty/blank lines from a file in Unix (including spaces)?
- Mount CIFS Host is down
- List of files installed from apt package
- How can I kill all stopped jobs?
- How to copy a large number of files quickly between two servers
- How to copy file preserving directory path in Linux?
- Postfix – how to retry delivery of mail in queue?
- Allow SFTP but disallow SSH?
- Is it possible to alias a hostname in Linux?
- How do I list loaded Linux module parameter values?
- Does getting disconnected from an SSH session kill your programs?
- Tips for Securing a LAMP Server
- What Linux distribution is the Amazon Linux AMI based on?
- What is this IP address: 169.254.169.254?
- How can I export the privileges from MySQL and then import to a new server?
- Is there a directory equivalent of /dev/null in Linux?
- Can I send some text to the STDIN of an active process running in a screen session?
- How can I get processor/RAM/disk specs from the Linux command Line? [duplicate]
- Should I install Linux applications in /var or /opt?
- Heartbleed: how to reliably and portably check the OpenSSL version?
- How can I fully log all bash scripts actions?
- Testing UDP port connectivity
- memcache vs memcached?
- zcat/gzcat works in linux, not on osx. general linux/osx compatibility
- What is the debian-sys-maint MySQL user (and more)?