I'm attempting to combine Scott Lowe's guide to creating a namespace with this answer on forwarding traffic between two interfaces.
I have this script that runs on each reboot using the cron @reboot directive: (I am using the script because none of these commands seem to persist across reboots.)
# Setup VPN
ip netns add vpnspace
ip link add vpnopen type veth peer name vpnbind
ip link set vpnopen netns vpnspace
ip netns exec vpnspace ifconfig vpnopen 10.0.0.1/24 up
When I run the script manually using sudo
, it executes fine. However, when the script is run by cron, the fourth line, ip netns exec vpnspace ifconfig vpnopen 10.0.0.1/24 up
, does not execute. Why is this happening? How do I get it to execute?
TL;DR: ifconfig vpnopen 10.0.0.1/24 up
doesn't execute when called by cron inside a namespace
=============
Clarifications:
- My cron job is
@reboot /home/ubuntu/startupscripts/rootscripts.sh
- The code given above is the first part of the shell script called
- By "does not execute", I mean that if I run command
sudo ip netns exec vpnspace ifconfig
in the terminal to check if the IP address was brought up, terminal returns a blank output. I tried logging the output by appending>>rootscripts.log
, but nothing is logged and no error message returned.
Best Answer
cron commands usually execute with a default PATH. While ip is typically in /bin, ifconfig is most often found in /sbin . . . so try putting /sbin/ifconfig in your command line.