Forwarding between two different servers Enable port forwarding First, enable the IP forwarding function, which is disabled by default. Temporary modification: [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward The modification will take effect immediately, but will return to the default value of 0 after the system is restarted. Permanent modification: vi /etc/sysctl.conf # Find the following value and change 0 to 1 net.ipv4.ip_forward = 1 The default value 0 disables IP forwarding, and changing it to 1 enables the IP forwarding function. Configure port forwarding Suppose when a user accesses First, open port 8804 on the server Modify the configuration file: vim /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8804 -j ACCEPT Or execute and save from command line [root@localhost sysconfig]# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8804 -j ACCEPT [root@localhost sysconfig]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[OK] Port forwarding Method 1: Command line execution Need to save, otherwise it will only take effect immediately, and the firewall rules will be cleared after restart iptables -t nat -A PREROUTING -d iptables -t nat -A POSTROUTING -d The command to save without changing the configuration file: service iptables save Method 2: Save directly to the configuration file Modify the /etc/sysconfig/iptables configuration file and add rules -A PREROUTING -d -A POSTROUTING -d After configuration, restart the firewall: 1.systemctl restart iptables (centos7); 2.service iptables restart (centos7 and previous versions) View the configured policies iptables -t nat --list --line-numbers Local port forwarding If you only need to forward ports between different machines, it is relatively easy. For example, if I visit http://ip:8888 and want to return the content of http://ip:6666, the configuration is as follows: [root@localhost ~]# iptables -t nat -A PREROUTING -p tcp --dport 8888 -j REDIRECT --to-ports 6666 [root@localhost ~]# service iptables save [root@localhost ~]# service iptables restart The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of WeChat Mini Program official face verification
>>: Database query optimization: subquery optimization
Table of contents 1. In project development, the ...
This article shares the installation and configur...
Table of contents 1. Create a table 1.1. Basic sy...
This article describes how to implement coexisten...
This article summarizes the common commands for L...
1. Build a Docker environment 1. Create a Dockerf...
CSS Styles html,body{ width: 100%; height: 100%; ...
1. The first parameter props of the setUp functio...
1. Transactions have ACID characteristics Atomici...
<frameset></frameset> is familiar to e...
Table of contents 1. writable: writable 2. enumer...
Let's take a look at zabbix monitoring sqlser...
1 Question The company's server uses Apache, ...
Core code -- Below I will demonstrate the impleme...
Uninstall MySQL 1. In the control panel, uninstal...