memo.log

技術情報の雑なメモ

コマンドで TUN/TAP デバイスを試すメモ

VPN(トンネル)技術のポイントにTUN/TAPデバイスというのがあるということで、少し触ってみた。イマイチ良くはわかっていない。

TUN

# TUN デバイス作成
% sudo ip tuntap add dev kure_tun mode tun 
% ip link show
9: kure_tun: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default 
qlen 500
    link/none
# どういうIFなのだ…?
% ifconfig kure_tun
kure_tun: flags=4240<POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# IPアドレスを設定してみる
% sudo ifconfig kure_tun 172.31.7.57 netmask 255.255.240.0
% ifconfig kure_tun
kure_tun: flags=4241<UP,POINTOPOINT,NOARP,MULTICAST>  mtu 1500
        inet 172.31.7.57  netmask 255.255.240.0  destination 172.31.7.57
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UN
SPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# ping も返ってくる
 % ping 172.31.7.57                           
PING 172.31.7.57 (172.31.7.57) 56(84) bytes of data.
64 bytes from 172.31.7.57: icmp_seq=1 ttl=255 time=0.030 ms

TAP

% sudo ip tuntap add dev kure_tap mode tap
# こっちはMACアドレスがついてる
% ifconfig kure_tap
kure_tap: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 9e:53:c6:5c:63:df  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# 同じ感じでIPアドレスも付けられるし、pingも返ってくる
% sudo ifconfig kure_tap 172.31.7.57 netmask 255.255.240.0
% ifconfig kure_tap                                       
kure_tap: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.31.7.57  netmask 255.255.240.0  broadcast 172.31.15.255
        ether 9e:53:c6:5c:63:df  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

消す時

sudo ip tuntap del dev tun0 mode tun   

参考/メモ

hogem.hatenablog.com

hichtakk.hateblo.jp

https://www.kernel.org/doc/Documentation/networking/tuntap.txt →一番オフィシャルなドキュメントぽい。

vtun.sourceforge.net →上記ドキュメントからリンクされているサンプルアプリ的な。

そもそもPoint to Point Interface というのがあるっぽい?→TUN

www.oreilly.com

unix.stackexchange.comイーサネットはポイントツーマルチ、TUNはポイントツーポイント

stackoverflow.com