Skip to content

TUN Pre and Post UP

Jason Lyu edited this page Feb 19, 2024 · 1 revision

Sometimes we want to run some commands before or after the TUN device is started, so there are two tun-pre-up and tun-post-up args that can be used in such scenarios.

  • TUN-Pre-UP: The commands specified in the tun-pre-up option are executed before the TUN device is created.
  • TUN-Post-UP: The commands specified in the tun-post-up option are executed after the TUN device has been created.

For example, if we want to run a script to automatically configure the ip address for our interface addresses and routes, we can use tun-post-up arg like this:

--tun-post-up "./your_script.sh"

Please note that the script you provided must have the execution permission.

Multiple Commands

If we want to run multiple commands with tun-pre-up or tun-post-up args, we can call a shell to do the trick, e.g.:

--tun-post-up "sh -c 'echo 1234567890 > a.txt && ./run_some_scripts.sh && rm -rf a.txt'"

OR in Windows:

--tun-post-up "powershell -Command 'command1 ; command2 ; command3'"
Clone this wiki locally