问题原文
原帖链接 · Zaden · CC BY-SA 3.0
I’m currently routing some marked packets via eth0. However, I have to apply the routing rules every time the system reboots. The two commands I always have to re enter are
ip rule add fwmark 3 table 3
ip route add default via 192.168.0.1 table 3
The gateway for eth0 being 192.168.0.1 I’ve tried placing those commands in both /etc/rc.local and /etc/network/interfaces, and in both cases I have still had to run them manually. Does anyone have a suggestion as to where/how to run these commands on every startup?
社区高分解答
原帖链接 · user9517 · CC BY-SA 3.0
Put your commands in a shell script e.g. /usr/local/sbin/myrouting and make it executable.
You could use cron and an @reboot target in /etc/crontab or the root crontab e.g. /etc/crontab
@reboot root /usr/local/sbin/myrouting
or root crontab
@reboot /usr/local/sbin/myrouting
You could also do it using systemd.
Create a systemd unit file /etc/systemd/system/myrouting.service
[Unit]
after=network
[Service]
ExecStart=/usr/local/sbin/myrouting
[Install]
WantedBy=default.target
Then enable it
systemctl enable myrouying.service
Created symlink /etc/systemd/system/default.target.wants/myrouting.service → /etc/systemd/system/myrouting.service.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
