RHEL 网络配置 --- IP转发

一、概要

1. 环境

Rocky Linux 9.1

CentOS 7.9

二、配置

1. sysctl服务

(1) 检查状态

systemctl status sysctl

(2) 开启

sudo systemctl start sysctl
sudo systemctl enable sysctl

2. 临时操作IP转发

(1) 查看状态

sysctl net.ipv4.ip_forward

输出net.ipv4.ip_forward = 0,0代表关闭,1代表开启。

(2) 开启IP转发

sudo sysctl -w net.ipv4.ip_forward=1

(3) 关闭IP转发

sysctl -w net.ipv4.ip_forward=0

(4) 应用配置

sudo sysctl -p 

注意,该配置将在network重启后失效。

3. 永久操作IP转发

(1) 编辑

sudo vi /etc/sysctl.conf

(2) 新增/修改

net.ipv4.ip_forward = 1

(3) 退出后重启

sudo systemctl restart network

三、参考

1. 官方

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/kernel_administration_guide/working_with_sysctl_and_kernel_tunables

2. 其他

https://linuxconfig.org/how-to-turn-on-off-ip-forwarding-in-linux

https://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/

posted @ 2023-06-23 11:35  白马黑衣  阅读(355)  评论(0编辑  收藏  举报