title: How do I set an ip address for TUN interface on OSX (without destination address)?
body: <p>How do I set an IP address for a TUN interface on OSX? I cannot figure out how to set up an ip address for my interface without specifying a destination IP. I don't want to do that- I'm want to more or less build a tunnel to an arbitrary address at a later point in time. Prior questions which are unhelpful:</p>
  
  <ol>
  <li>There's <a href="https://serverfault.com/questions/463166/how-to-make-a-tun-interface-with-ifconfig-in-osx">a question</a> that has an unclear answer, so I tried following the reference. </li>
  <li><a href="https://stackoverflow.com/questions/13035220/interfacing-with-tun-tap-for-mac-osx-lion-using-python?rq=1">This question</a> sets a point to point ip address for a tun device, so it has a destination, which is exactly what I don't want.</li>
  </ol>
  
  <p>On the page for <a href="http://tuntaposx.sourceforge.net/faq.xhtml" rel="nofollow noreferrer">osxtuntap</a> it says:</p>
  
  <pre><code>ifconfig tap0 10.1.2.3 up
  </code></pre>
  
  <p>I cannot make this work on OSX 10.6 for a TUN interface:</p>
  
  <pre><code>$ sudo ifconfig tun0 10.1.2.3 up
  ifconfig: ioctl (SIOCAIFADDR): Destination address required
  </code></pre>
  
  <p>Adding a netmask doesn't help- OSX seems to demand a destination address:</p>
  
  <pre><code>$ ifconfig tun0 10.0.0.1/24 netmask 255.255.255.0
  ifconfig: ioctl (SIOCAIFADDR): Destination address required
  </code></pre>
  
  <p>For linux, I get how it works. According to <a href="http://backreference.org/2010/03/26/tuntap-interface-tutorial/" rel="nofollow noreferrer">this page</a>, you open() the interface, and use the ip command, and do this, and I've done this before with zero issues:</p>
  
  <pre><code>$ ip link set tun0 up
  $ ip addr add 10.0.0.1/24 dev tun0
  </code></pre>
  
  <p>All I want to do is the same thing that I can do in linux.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>I'm writing a little UDP tunnel app. Like so:</p>
  
  <p>tun1 -> udp app #1 -> udp tunnel -> udp app #2 -> tun2</p>
  
  <p>If the udp apps are on different computers (let's say local and remote), I'd like to associate their respective tun devices with an ip address, so I can send a packet from local to remote via the tunnel by sending the packet to the ip address of the tun device on the remove machine. </p>
  
  <p>To borrow more from the linux tutorial, the author sets up a tun device on local and remote, associates ips, and runs a simple tunneling app, and then pings the other end of the tunnel:</p>
  
  <pre><code>[remote]# ip link set tun3 up
  [remote]# ip addr add 192.168.0.2/24 dev tun3
  [remote]$ ./simpletun -i tun3 -s
  # server blocks waiting for the client to connect
  [local]# ip link set tun11 up
  [local]# ip addr add 192.168.0.1/24 dev tun11
  [local]$ ./simpletun -i tun11 -c 10.2.3.4
  # nothing happens, but the peers are now connected
  [local]$ ping 192.168.0.2
  </code></pre>