記一次Multicast DNS(mdns)的問題-(linux 下ifconfig),mdnsifconfig
前言:近期在查詢mdns的問題過程一波三折,問題總結下來可以分為三塊,都是比較基礎性的問題:
1.網關ifconfig查詢地址
2.多個程式同時佔用一個連接埠號碼佔用編碼問題
3.mdns協議及實現源碼
mdns是用於區域網路發現的一種協議,網關搭載的linux系統,首先得確定其使用的是哪個地址作為通訊,說一個最簡單的指令:ifconfig,雖然早就知道這個指令,但是其實這個指令包含比較多的基礎知識。
用我使用的openwrt路由器輸入ifconfig:
br-lan Link encap:Ethernet HWaddr 04:A1:51:9A:03:67 inet addr:198.100.100.1 Bcast:198.100.100.255 Mask:255.255.255.0 inet6 addr: fdbb:e076:9029::1/60 Scope:Global inet6 addr: fe80::6a1:51ff:fe9a:367/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:37358673 errors:0 dropped:0 overruns:0 frame:0 TX packets:49805372 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:10001210378 (9.3 GiB) TX bytes:49536338006 (46.1 GiB)eth0 Link encap:Ethernet HWaddr BE:7F:7D:5D:09:D9 inet6 addr: fe80::bc7f:7dff:fe5d:9d9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:71274265 errors:0 dropped:0 overruns:383 frame:0 TX packets:67972711 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:23375869 (22.2 MiB) TX bytes:4047624223 (3.7 GiB) Interrupt:4 eth0.1 Link encap:Ethernet HWaddr BE:7F:7D:5D:09:D9 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:27485423 errors:0 dropped:0 overruns:0 frame:0 TX packets:32246955 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8388027931 (7.8 GiB) TX bytes:32142311436 (29.9 GiB)eth0.2 Link encap:Ethernet HWaddr 04:A1:51:9A:03:68 inet addr:193.168.1.125 Bcast:193.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::6a1:51ff:fe9a:368/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:43788842 errors:0 dropped:0 overruns:0 frame:0 TX packets:35727507 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:46186987470 (43.0 GiB) TX bytes:10288278423 (9.5 GiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:10489 errors:0 dropped:0 overruns:0 frame:0 TX packets:10489 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1066479 (1.0 MiB) TX bytes:1066479 (1.0 MiB)wlan0 Link encap:Ethernet HWaddr 04:A1:51:9A:03:67 inet6 addr: fe80::6a1:51ff:fe9a:367/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4839004 errors:0 dropped:0 overruns:0 frame:0 TX packets:5852922 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:670518236 (639.4 MiB) TX bytes:1589348208 (1.4 GiB)wlan1 Link encap:Ethernet HWaddr 04:A1:51:9A:03:69 inet6 addr: fe80::6a1:51ff:fe9a:369/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5443036 errors:0 dropped:0 overruns:0 frame:0 TX packets:9474688 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1115674576 (1.0 GiB) TX bytes:1268032438 (1.1 GiB)
此處br-lan,eth0,eth0.1…代表的是什麼意思呢?
通過查閱,知道了其實在系統檔案(network ,wireless)中針對有線和無線早有配置。
root@OpenWrt:/etc/config# cat network config interface 'loopback' option ifname 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0'config globals 'globals' option ula_prefix 'fdbb:e076:9029::/48'config interface 'lan' option ifname 'eth0.1' option force_link '1' option type 'bridge' option proto 'static' option netmask '255.255.255.0' option ip6assign '60' option macaddr '04:a1:51:9a:03:67' option ipaddr '198.100.100.1'config interface 'wan' option ifname 'eth0.2' option proto 'dhcp' option macaddr '04:a1:51:9a:03:68'config interface 'wan6' option ifname 'eth0.2' option proto 'dhcpv6'config switch option name 'switch0' option reset '1' option enable_vlan '1'config switch_vlan option device 'switch0' option vlan '1' option ports '0t 1 2 3 4'config switch_vlan option device 'switch0' option vlan '2' option ports '0t 5'root@OpenWrt:/etc/config# cat wireless config wifi-device 'radio0' option type 'mac80211' option hwmode '11g' option path 'platform/ar934x_wmac' option htmode 'HT20' option txpower '22' option country 'US' option channel '6'config wifi-device 'radio1' option type 'mac80211' option channel '36' option hwmode '11a' option path 'pci0000:00/0000:00:00.0' option htmode 'HT20' option txpower '14' option country 'US'config wifi-iface option device 'radio1' option network 'lan' option mode 'ap' option ssid 'jthlw-cj5G' option encryption 'psk-mixed' option key '11223344'config wifi-iface option device 'radio0' option mode 'ap' option network 'lan' option ssid 'jthlw-cj' option encryption 'psk-mixed' option key 'cjcjcj12345'
首先粘貼一張盜版的openwrt的架構:
網關的兩個網卡:eth0,eht2分別為一個有線一個無線網卡,這是兩個真實的網卡,是有對應的mac地址的。
通過配置
config interface 'lan' option ifname 'eth0.1' option force_link '1' option type 'bridge' option proto 'static' option netmask '255.255.255.0' option ip6assign '60' option macaddr '04:a1:51:9a:03:67' option ipaddr '198.100.100.1' config interface 'wan' option ifname 'eth0.2' option proto 'dhcp' option macaddr '04:a1:51:9a:03:68'
可以看出:eth0是有線網卡,eth0.1,eth0.2從上面通過switch虛擬出來,eth0.1對應LAN口,eth0.2對應WAN口,其地址都可以手動修改。
而radio0, radio1對應的是無線網卡(2.4G ,5G)
而br-lan是虛擬出來的,用於統一管理LAN
root@OpenWrt:/etc/config# brctl showbridge name bridge id STP enabled interfacesbr-lan 7fff.04a1519a0367 no eth0.1 wlan1 wlan0
所以可以看出,eth0.2用於WAN口,其上一級的IP為:193.168.1.125;eth0.1用於管理LAN口,子LAN口的IP都由198.100.100.1進行分配。
(以上只是自己對網關很淺的一些認識,更多的可以關注下面引用的部落格,並且諸如防火牆(firewall的設定可以參見:、etc/config 下面的firewall檔案)))