OpenVPN: Can’t assign requested address

For no clear reason, OpenVPN on Mac with Tunnelblick (any version, had this problem for a few years already) results in these kind of error messages (and refuses to connect):

2013-02-05 17:44:31 write UDPv4: Can't assign requested address (code=49)
2013-02-05 17:44:33 write UDPv4: Can't assign requested address (code=49)

This seems to appear more often when swapping WiFi/IP range (after my Mac goes into sleep). But also happens when connecting to the same WiFi. It doesn’t change anything whether I disconnect OpenVPN before putting the Mac to sleep.

The solution I’ve found to solve this is:

  1. Disconnect OpenVPN (via Tunnelblick)
  2. Turn off WiFi
  3. Run the script I’ve attached below (flush.sh)
  4. Fill in your admin/sudo password
  5. Hit ctrl+C if it doesn’t exit instantly (happens in 99% of the cases)
  6. Run the script once or twice more to be sure, it will exit correctly this time
  7. Reconnect to the WiFi
  8. Reconnect OpenVPN (via Tunnelblick): this time it will work

The script (name it flush.sh, chmod +x, and run ./flush.sh via Terminal):

Edit: updated script (29/01/2014)

#!/bin/bash
# Change IFACE to match your WiFi interface 
# (en0 on Macbook Air and Retina, en1 on old Macbook Pros with ethernet) 
IFACE=en0
sudo ifconfig $IFACE down
sudo route flush
sudo ifconfig $IFACE up

In case the script hangs (sometimes, route flush hangs): hit ctrl+C, and execute it again.


Posted by

in

, , , ,

Comments

4 responses to “OpenVPN: Can’t assign requested address”

  1. tania avatar
    tania

    it doesn’t work to me this solution

  2. Yeri Tiete avatar

    Maybe you’re not using en0 as interface (wifi probably). Be sure to modify it.

  3. allen avatar
    allen

    Change “sudo route flush” to “sudo route -n flush” works for me, and there would be no hangs.

  4. Ludo avatar
    Ludo

    Great find, thanks!

Leave a Reply…