如何在 Linux 中设置 USB/以太网接口?

如何在 Linux 中设置 USB/以太网接口?
me@me:~$ sudo /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
me@me:~$ sudo service network-manager restart
me@me:~$ sudo ifup eno1
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eno1/34:e6:d7:0a:8f:fc
Sending on   LPF/eno1/34:e6:d7:0a:8f:fc
Sending on   Socket/fallback
DHCPDISCOVER on eno1 to 255.255.255.255 port 67 interval 3 (xid=0x162c3b49)
DHCPDISCOVER on eno1 to 255.255.255.255 port 67 interval 7 (xid=0x162c3b49)
DHCPREQUEST of 134.94.232.12 on eno1 to 255.255.255.255 port 67 (xid=0x493b2c16)
DHCPOFFER of 134.94.232.12 from 134.94.232.1
DHCPACK of 134.94.232.12 from 134.94.232.1
bound to 134.94.232.12 -- renewal in 282886 seconds.

me@me:~$ ifconfig -a
eno1      Link encap:Ethernet  HWaddr 34:e6:d7:0a:8f:fc  
          inet addr:134.94.232.12  Bcast:134.94.239.255  Mask:255.255.248.0
          inet6 addr: fe80::36e6:d7ff:fe0a:8ffc/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12414 errors:0 dropped:2 overruns:0 frame:0
          TX packets:4826 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8676664 (8.6 MB)  TX bytes:536959 (536.9 KB)
          Interrupt:20 Memory:f7e00000-f7e20000 

enx00116b68261f Link encap:Ethernet  HWaddr 00:11:6b:68:26:1f  
          inet addr:192.168.1.21  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::1851:f4a:198:2c2f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:44 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:64 (64.0 B)  TX bytes:6860 (6.8 KB)

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:3656 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3656 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:285972 (285.9 KB)  TX bytes:285972 (285.9 KB)

wlp2s0    Link encap:Ethernet  HWaddr 60:57:18:0d:ec:06  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

me@me:~$ sudo lshw -C network  *-network               
       description: Ethernet interface
       product: Ethernet Connection (3) I218-LM
       vendor: Intel Corporation
       physical id: 19
       bus info: pci@0000:00:19.0
       logical name: eno1
       version: 04
       serial: 34:e6:d7:0a:8f:fc
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 32 bits
       clock: 33MHz
       capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k duplex=full firmware=0.2-3 ip=134.94.232.12 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:47 memory:f7e00000-f7e1ffff memory:f7e43000-f7e43fff ioport:f080(size=32)
  *-network DISABLED
       description: Wireless interface
       product: Wireless 7265
       vendor: Intel Corporation
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: wlp2s0
       version: 3b
       serial: 60:57:18:0d:ec:06
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=iwlwifi driverversion=4.4.0-91-generic firmware=17.459231.0 latency=0 link=no multicast=yes wireless=IEEE 802.11abgn
       resources: irq:52 memory:f7c00000-f7c01fff
  *-network
       description: Ethernet interface
       physical id: 2
       logical name: enx00116b68261f
       serial: 00:11:6b:68:26:1f
       size: 1Gbit/s
       capacity: 1Gbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=ax88179_178a driverversion=22-Aug-2005 duplex=full firmware=ASIX AX88179 USB 3.0 Gigabit Et ip=192.168.1.21 link=yes multicast=yes port=MII speed=1Gbit/s
me@me:~$ sudo ping 192.168.1.14 -c3
PING 192.168.1.14 (192.168.1.14) 56(84) bytes of data.

--- 192.168.1.14 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

me@me:~$ sudo ifup enx00116b68261f
Unknown interface enx00116b68261f

我有一个 USB 转以太网适配器连接到我的 Linux 系统。我编辑了连接信息,并192.168.1.21在右上角的连接菜单中给出了手动 IP。在上面的命令行中,我们可以看到我的系统上可用的连接信息。我无法为en0016b68261f.以下是我的界面/etc/network

interfaces(5) file used by ifup(8) and ifdown(8)

#The loopback network interface

auto lo
iface lo inet loopback

# The primary network interface
iface eno1 inet dhcp

当我尝试 ping USB 转以太网适配器另一端的端口(其 IP 地址为 192.168.1.14)时,我无法 ping 通我的开发板的该 IP 地址。

如何设置我的 USB 转以太网适配器?

Traceroute 显示了这一点:

me@me:/$ traceroute 192.168.1.21
traceroute to 192.168.1.21 (192.168.1.21), 30 hops max, 60 byte packets
 1  192.168.1.21 (192.168.1.21)  0.231 ms  0.192 ms  0.180 ms
me@me:/$ traceroute 192.168.1.14
traceroute to 192.168.1.14 (192.168.1.14), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 (...)
29  * * *
30  * * *

答案1

有很多解决方案。主要是,您在 Linux GUI 上使用 NetworkManager,这有什么用处。

实际上,有两个系统执行同一任务:

  1. 他们正在使用系统范围的网络配置脚本/etc/network/interfaces
  2. 还有一个NetworkManager,它是一个用于相同任务的 GUI 工具,但它也有每个用户的配置。

您的配置存在冲突,您想尝试同时配置它们。

这个答案解释了如何通过系统范围的引导脚本来执行此操作。

这里的主要问题是,USB/以太网设备不是固定设备,但您可以随时插入和拔出。

  1. 避免对 USB 设备进行可怕的接口重命名,并为其指定一个修复名称。描述的是这里, 如何。本质上,把这条线

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="01:23:45:67:89:ab", NAME="usb0"

进入你的/etc/udev/rules.d/70-persistent-net.rules.结果将是你的USB 设备(由其 MAC 标识)将始终为usb0.

  1. 那么你就要消除这个东西对NetworkManager的影响。作为这里解释了吗,很简单,它只是忽略了现有的设备/etc/network/interfaces。只需配置一下即可,例如您可以给他一个静态 IP,或者配置一个 dhcp:
auto usb0 #iface usb0 inet dhcp #iface usb0 inet static # address 192.168.220.65 # netmask 255.255.255.224 # broadcast 192.168.220.95

正如它所写的这里,您可以使用以下命令重新加载 udev 规则,而无需重新启动

# udevadm control --reload-rules && udevadm trigger

作为根。

相关内容