大网数据广告活动
服务器运维问答

Where to save ip rule, ip route and iptables commands on Debian Stretch?

· 52CE 我爱测

To make an SSH server work properly while still maintaining an OpenVPN connection, I have a small mixture of ip -related commands I need to persist and run on startup on a Debian Stretch (actually Raspbian) machine: iptables -t m…

问题原文

原帖链接 · Roxy · CC BY-SA 3.0

To make an SSH server work properly while still maintaining an OpenVPN connection, I have a small mixture of ip-related commands I need to persist and run on startup on a Debian Stretch (actually Raspbian) machine:

iptables -t mangle -A PREROUTING -i "${INTERFACE}" -m conntrack --ctstate NEW -j CONNMARK --set-mark 1234
iptables -t mangle -A OUTPUT -m connmark --mark 1234 -j MARK --set-mark 4321
ip route add default dev "${INTERFACE}" table 1000
ip rule add fwmark 4321 table 1000

INTERFACE is a variable for the default device to use.

Where is the appropriate place to put these commands so that they are automatically executed when the system boots?

已采纳解答

原帖链接 · Khaled · CC BY-SA 3.0

On Debian-based systems, you can find a package iptables-persistent. This package enables you to easily save your current iptables rules to be loaded at system startup.

For routing related commands, you can execute them as post-up commands in the network interfaces configuration file. Here is a related post.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。