0

Here is the command to assign IP address to an interface for Linux server.

ip addr add ADDRESS dev IFNAME

Where IFNAME is the interface name and ADDRESS is the IP address you want to assign to the interface.

To add address 192.168.121.45 with netmask 24 to device eth0, you would type:

sudo ip address add 192.168.121.45/24 dev eth0

NIC belongs to the physical layer, IP belongs to the IP layer, they are independent. I would like to ask further questions to figure out the relation between NIC and IP address.

  • Is the NIC prerequisite of IP address?
  • Must IP address be attached to a NIC?
  • Can ip address live alone on IP layer without NIC?

Reference

  1. Linux ip Command: Assign IP addresses to an interface
  2. serverFault: Can a single network card have 2 IP addresses?
Ryan Lyu
  • 103
  • 4
  • 1
    Hi, please edit your question as your question is unclear. Please specify your goal. As a switch can route with a IP, even if it's not bind to a NIC. – yagmoth555 Apr 05 '22 at 02:37
  • Hi @yagmoth555, Thanks for your feedback. I have made the question more concrete. I will reopen it if you think the detail is adequate. – Ryan Lyu Apr 05 '22 at 03:10
  • @RyanLyu Define *NIC* - physical interface? logical/virtual interface? – Zac67 Apr 05 '22 at 07:05
  • Hi @Zac67, in this place, NIC is general. I am trying to figure out the relation between NIC and IP addresses and assuming NIC is the container of IP addresses. I will appreciate if you could provide your insights. – Ryan Lyu Apr 05 '22 at 07:48
  • 1
    https://unix.stackexchange.com/questions/152331/how-can-i-create-a-virtual-ethernet-interface-on-a-machine-without-a-physical-ad will answer this quetion :) and to be honestly, a NIC does only provide connectivity, the protocol is a other layer, remind the OSI model – djdomi Apr 05 '22 at 07:52

1 Answers1

2

You don't necessarily need a NIC (physical interface). You need an interface though, either physical, logical or virtual.

There are loopback interfaces, built into the local TCP/IP stack, virtual NICs (vNICs) for virtual machines, switch virtual interfaces (SVIs) for routing on layer-3 switches, TUN/TAP interfaces for VPN, and many other types of virtual interfaces.

Zac67
  • 8,639
  • 2
  • 10
  • 28