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?
5
  • 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 5, 2022 at 2: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 5, 2022 at 3:10
  • @RyanLyu Define NIC - physical interface? logical/virtual interface?
    – Zac67
    Apr 5, 2022 at 7: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 5, 2022 at 7:48
  • 1
    unix.stackexchange.com/questions/152331/… 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 5, 2022 at 7:52

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .