1. 程式人生 > >將ARM4412開發板配置成USB網絡卡,並且使用USB通過Ubuntu上網

將ARM4412開發板配置成USB網絡卡,並且使用USB通過Ubuntu上網

注:以下配置在三星s4手機也成功測試通過,可以ping通外網ip和域名,但是瀏覽器不能上網。 1. 開發板4412 linux核心配置 4412需要安裝USB Gadget驅動g_ether.ko(drivers/usb/gadget/ether.c) 來進行通訊。g_ether.ko在配置選單位置如下:
  1. │ -> Device Drivers │
  2. │ -> USB support (USB_SUPPORT [=y]) │
  3. │ -> USB Gadget Support (USB_GADGET [=y]) │
  4. │ -> USB Gadget Drivers ( [=y]) │
  5. │ -> Ethernet Gadget (with CDC Ethernet support)
make後下載到開發板。(注:可以以模組或是靜態編譯的方式來配置,靜態編譯方式測試通過。) 開發板通過USB連線到電腦後,在PC端Ubuntu下輸入ifconfig 便可看到usb0的網路介面:
2. 4412開發板配置: 在超級終端下輸入 1)設定介面:ifconfig usb0 192.168.2.2(注意不能和eth0的ip處於同一網段) 2)配置閘道器:route add default gw 192.168.2.1 3)設定DNS: vi /etc/resolv.conf,修改成 nameserver 114.114.114.114
注:能ping外網ip但不能ping域名基本都是DNS沒有設定好。 另注:三星S4通過setprop無法ping外網域名,只有修改nameserver才可以ping通。 3. PC端Ubuntu設定: sysctl -w net.ipv4.ip_forward=1 iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE ifconfig usb0 192.168.2.1 netmask 255.255.255.0
命令依次的含義是:開啟IP轉發,允許usb0到eth0的包通過防火牆,在伺服器上設定了對於客戶端的NAT,設定usb0網絡卡的ip地址
4. 4412 開發板ping外網測試 注:這裡需要確保pc以及連上外網。
5. 開發板和Ubuntu互ping 開發板和Ubuntu相互ping通只需設定以下兩項即可,不需要上述2、3繁瑣步驟: 4412開發板:ifconfig usb0 192.168.2.2 Ubuntu:ifconfig usb0 192.168.2.1 Ubuntu下ping開發板測試結果:
6. 參考: 1.Android手機通過USB資料線共享Linux電腦網路(internet傳輸) 2.Linux手機如何通過usbnet訪問internet 3.Linux 下使用USB 網路-精華 7. 附usbview 4412開發板USB配置詳情: Manufacturer: Linux 3.0.15 with s3c-udc Speed: 480Mb/s (high) USB Version: 2.00 Device Class: 02(comm.) Device Subclass: 00 Device Protocol: 00 Maximum Default Endpoint Size: 64 Number of Configurations: 2 Vendor Id: 0525 Product Id: a4a2 Revision Number: 3.26 Config Number: 2 Number of Interfaces: 2 Attributes: c0 MaxPower Needed: 2mA Interface Number: 0 Name: Alternate Number: 0 Class: 02(comm.) Sub Class: 02 Protocol: ff Number of Endpoints: 1 Endpoint Address: 83 Direction: in Attribute: 3 Type: Int. Max Packet Size: 8 Interval: 32ms Interface Number: 1 Name: Alternate Number: 0 Class: 0a(data ) Sub Class: 00 Protocol: 00 Number of Endpoints: 2 Endpoint Address: 82 Direction: in Attribute: 2 Type: Bulk Max Packet Size: 512 Interval: 0ms Endpoint Address: 01 Direction: out Attribute: 2 Type: Bulk Max Packet Size: 512 Interval: 0ms Config Number: 1 Number of Interfaces: 2 Attributes: c0 MaxPower Needed: 2mA Interface Number: 0 Name: cdc_ether Alternate Number: 0 Class: 02(comm.) Sub Class: 06 Protocol: 00 Number of Endpoints: 1 Endpoint Address: 83 Direction: in Attribute: 3 Type: Int. Max Packet Size: 16 Interval: 32ms Interface Number: 1 Name: cdc_ether Alternate Number: 0 Class: 0a(data ) Sub Class: 00 Protocol: 00 Number of Endpoints: 0 Interface Number: 1 Name: cdc_ether Alternate Number: 1 Class: 0a(data ) Sub Class: 00 Protocol: 00 Number of Endpoints: 2 Endpoint Address: 82 Direction: in Attribute: 2 Type: Bulk Max Packet Size: 512 Interval: 0ms Endpoint Address: 01 Direction: out Attribute: 2 Type: Bulk Max Packet Size: 512 Interval: 0ms