Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use IP forwarding to connect the internal network to the Internet on Linux

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly analyzes the relevant knowledge points on Linux how to use IP forwarding to connect the internal network to the Internet, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor and learn more about "how to use IP forwarding to connect the internal network to the Internet on Linux".

1. To enable IPv4 forwarding first, we need to enable IPv4 forwarding on our Linux operating system. To do this, we need to use sudo mode to execute the following command under shell or terminal.

$sudo-s # echo 1 > / proc/sys/net/ipv4/ip_forward

Note: the above command enables ip forwarding immediately, but only temporarily until the next restart. To enable it permanently, we need to open the / etc/sysctl.conf file using our usual text editor.

# nano / etc/sysctl.conf then add net.ipv4.ip_forward = 1 to the file, or delete the comment on that line, save and exit the file.

Net.ipv4.ip_forward = 1

Run the following command to enable changes.

# sysctl-p / etc/sysctl.conf

two。 To configure the Iptables firewall, we need to allow specific (or all) packets to pass through our router. Before that, we need to know the interface name of the network device that connects to our Linux. We can get the interface name by running the following command at the terminal or shell.

# ifconfig-a

Here, in our machine, eth3 is the interface of the network card connected to the Internet or network, and wlan2 is the interface through which we want to forward packets from eth3 using iptables. To achieve forwarding, we need to run the following command.

# iptables-A FORWARD-I wlan2-o eth3-j ACCEPT Note: please replace wlan2 and eth3 with the available device names on your Linux machine.

Now, since netfilter/iptables is a stateless firewall, we need to get iptables to allow established connections through. To do this, we need to run the following command.

# iptables-A FORWARD-I eth3-o wlan2-m state-- state ESTABLISHED,RELATED-j ACCEPT

3. After configuring NAT, finally we need to change the source address of the packet sent to the Internet to eth3 by executing the following command.

# iptables-t nat-A POSTROUTING-o eth3-j MASQUERADE

What are the versions of Linux? the versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

On "how to use IP forwarding on Linux to connect the internal network to the Internet" is introduced here, more related content can be searched for previous articles, hope to help you answer questions, please support the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report