2

My workplace has several security policies that run counter to how I would usually set up my laptop. In particular, when connected to the network at work, we are forbidden from having an ssh daemon accepting connections. This generally leads to me getting in trouble at work (when I forget to shut down the sshd) or being unable to access my laptop remotely when it's not at work (when I forget to bring it back up), so I would like to automate this process.

Is there a way to automatically change the firewall rules or stop/start the sshd service depending on the SSID of the wifi network I am connected to? I am running CentOS6 if it makes a difference.

  • This may be easier to perform by IP. When you are connecting to your laptop remote you're using a static IP, correct? (to make the forward rule in the router) – grochmal Aug 20 '16 at 23:05
  • @grochmal No, I use my laptop on several different networks. On some it has a fixed IP behind NAT, but on others it is given a global IP address by DHCP. – Chris Aug 21 '16 at 0:32
1

If you are using the standard dhclient configuration of CentOS 6 then after DHCP has completed it will run a series of "post" scripts.

Of use, here, is the /etc/dhcp/dhclient.d directory. These scripts will be run after the IP address has been obtained.

It would be pretty simple to add a script in here that would look at your wireless setup (iwconfig) and decide whether to stop or start sshd or whether to permit/deny port 22, or anything else you would like.

See here for some information on how the scripts need to be set up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.