How to config USB ethernet to have a static IP?

16,190

If you need to plug/unplug very frequently, a HWaddr should bind to the device like this 12:a5:cf:42:92:fd. For my case, I'm using g_ether.ko on an embeded linux system, run "insmod g_ether.ko host_addr=12:a5:cf:42:92:fd dev_addr=5e:bc:ca:27:92:b1". Then on the linux host (Ubuntu 12.04 LTS for my case), edit the file "/etc/NetworkManager/system-connections/Wired connection 2", and input something like

####################################
[802-3-ethernet]

duplex=full
mac-address=12:a5:cf:42:92:fd

[connection]

id=Wired connection 2
uuid=2862a666-c2e6-4a3a-8e0c-8705d93c92da
type=802-3-ethernet
timestamp=1501735507

[ipv6]

method=auto

[ipv4]

method=manual

addresses1=192.168.42.21;24;192.168.42.1;
###############################################

Last, save the file, and plug/replug the usb cable.

Share:
16,190

Related videos on Youtube

user3528438
Author by

user3528438

Updated on September 18, 2022

Comments

  • user3528438
    user3528438 over 1 year

    I have a USB device that works as a USB RNDIS ethernet device.

    This device does not have DHCP capability so the host computer needs to allocate IP address for itself.

    I tried to add to the /etc/network/interfaces

    auto usb0
    iface usb0 inet static
        address 192.168.7.15
        netmask 255.255.255.0
        network 192.168.7.0
    

    Then I run into the problem similar to this one: when the device is not connected then usb0 will not show, and network-manager would fail at boot.

    Is there a way to work around this?

    • Pilot6
      Pilot6 over 8 years
      No devices have "DHCP capability". It is done by the OS. If you setup interface this way, NM will not manage it anyway. It is totally unclear what are you asking.
    • user3528438
      user3528438 over 8 years
      @Pilot6 I mean, when the device is connected to the host, the device can not allocate an IP address for the host.
  • user3528438
    user3528438 over 8 years
    Because this is a peer-to-peer direct connection and there is not DHCP server, so the two sides needs to allocate/configure IP address for themselves. I'm trying to hard code an IP address in /etc/network/interfaces which caused problems.
  • Ijaz Ahmad
    Ijaz Ahmad over 8 years
    Ok , remove network manager and then hard code it on both sides , they should be on the same subnet
  • user3528438
    user3528438 over 8 years
    Then how would other adapters work if network manager is disabled?
  • user3528438
    user3528438 over 8 years
    Well, I know this approach but everytime the device is connected, it creates a new connection, and I need to manually change the settings everytime. Since I need to plug/unplug and boot/reboot the device very frequently, I'm trying to figure out a way to make the settings persistent.
  • Ijaz Ahmad
    Ijaz Ahmad over 8 years
    I am using wireless adapter without NM. NM had many problems so i removed it
  • dobey
    dobey over 8 years
    That sounds like a bug in network-manager then, and you should report it.
  • user3528438
    user3528438 over 6 years
    You are right. The reason the host side can not remember the IP settings is the device side uses a different mac address each time the module is mounted. So the solution is to use module parameters to set a fixed mac, preferably a device unique value on boot and when the module is mounted.