Linux network configuration - port forwarding, firewall

NAT forwarding using iptables

Forward proxy and reverse proxy
https://blog.csdn.net/boyemachao/article/details/107059329
specific steps
https://www.cnblogs.com/justmine/p/10478722.html
different situations
https://zhuanlan .zhihu.com/p/42153839
https://blog.csdn.net/zzchances/article/details/124062478
Start iptables
https://zhuanlan.zhihu.com/p/482207507
Implement port forwarding through iptables in Linux
https:/ /zhuanlan.zhihu.com/p/165043421
Rule view, create and delete
https://www.freebuf.com/articles/web/289254.html
Before installation, confirm whether it has been installed
which iptables
whereis iptalbes

firewall

iptables, firewalld method
https://blog.csdn.net/y368769/article/details/104490697
ufw method
https://blog.51cto.com/u_15127647/4297560

iptables errors

  • Failed to enable unit: Unit file iptables.service does not exist.
    Systemd Service:
    Even after iptables is installed, some distributions might not come with a systemd service file for iptables. If that’s the case, you can use iptables commands directly without the systemd service, or you can manually create a systemd service for it.

If you choose to create one, here’s a basic example:

[Unit]
Description=Packet Filtering Framework
DefaultDependencies=no
Before=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecReload=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecStop=/usr/libexec/iptables/iptables.init save
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

Save the above contents to /etc/systemd/system/iptables.service and then reload the systemd daemon:

sudo systemctl daemon-reload

After resolving the issue, you can enable and start the service:

sudo systemctl enable iptables
sudo systemctl start iptables
  • Job for iptables.service failed because the control process exited with error code

Check the iptables.service unit file to ensure that the ExecStart directive contains a valid path to the iptables command. You can view the unit file using the command sudo systemctl cat iptables.

If you do not have the /etc/iptables/iptables.rules file and the /usr/sbin/iptables-restore command on your system, then first make sure you have iptables installed. On some systems, such as certain versions of Debian or Ubuntu, you may find iptables-restore in the /sbin/ directory instead of /usr/sbin/.

Here are suggested steps on how to deal with this problem:

1 Confirm the location of iptables-restore and iptables-save:

Use the which command to find out the exact paths of these commands:
which iptables-restore
which iptables-save
assumes the paths of these commands are /sbin/iptables-restore and /sbin/iptables-save.

2Choose a place to save the rule:

You can choose any place you like to store your iptables rules, but the /etc/ directory is generally recommended. For example, use the path /etc/iptables.rules.

/etc/iptables.rules is a file, not a folder. This file is used to store the iptables rule set so that these rules can be restored after a system restart.

When you first set up the iptables service, you need to create this file manually, unless you already have an existing rules file.

Here are the steps how to manually create and save the current iptables rules to this file:

Create the file (if it doesn't already exist):

sudo touch /etc/iptables.rules

3 Modify the systemd service file:

According to the above path, modify the ExecStart and ExecStop instructions of your /etc/systemd/system/iptables.service file:

ExecStart=/sbin/iptables-restore /etc/iptables.rules
ExecStop=/sbin/iptables-save > /etc/iptables.rules

4 Reload the systemd configuration:

sudo systemctl daemon-reload

Guess you like

Origin blog.csdn.net/xyl295528322/article/details/132053553