2

Lets say that I connect a device with a static IP in a switch. How does the switch know that there is new device connected? Does the device send an ICMP packet in order to tell that it is new on the switch/router? Is there any protocol to resolve this issue?

gravyface
  • 13,947
  • 16
  • 65
  • 100
ralu
  • 123
  • 1
  • 6

4 Answers4

11

Device may use ARP announcements,

ARP announcements

ARP may also be used as a simple announcement protocol. This is useful for updating other hosts' mapping of a hardware address when the sender's IP address or MAC address has changed. Such an announcement, also called a gratuitous ARP message, is usually broadcast as an ARP request containing the sender's protocol address (SPA) in the target field (TPA=SPA), with the target hardware address (THA) set to zero. An alternative is to broadcast an ARP reply with the sender's hardware and protocol addresses (SHA and SPA) duplicated in the target fields (TPA=SPA, THA=SHA).

ooshro
  • 10,874
  • 1
  • 31
  • 31
6

The switch learns which MAC addresses are connected to which ports in one of two ways:

  1. The switch sees traffic from a port from a MAC address not in it's MAC address table and records that MAC address/port combination in it's MAC address table.

  2. Traffic destined for a MAC address that the switch does not have in it's MAC address table is flooded to all switch ports and the switch records on which port the device with the destination MAC address responds and records that MAC address/port combination in it's MAC address table.

As the entries in the dynamic MAC address table will time out (default aging time of 300 seconds on Cisco switches) the process of building/rebuilding the dynamic MAC address table is a regularly occurring event. In addition, if the switches are configured for STP (Spanning Tree Protocol), a topology change (plugging a new device in to the switch on a port not configured for port-fast) will reduce the MAC address aging time to 15 seconds (again, in Cisco switches) and this can cause unneccessary switch flooding. That's why all ports to which hosts are connected should be configured for port-fast, so that switch flooding due to a topology change is not caused by plugging a new host in to a switch port.

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
2

I believe switches use the ARP protocol.

http://en.wikipedia.org/wiki/Address_Resolution_Protocol

Also check NDP

http://en.wikipedia.org/wiki/Neighbor_Discovery_Protocol

Hope this helps.

pablo
  • 3,020
  • 1
  • 18
  • 23
0

The switch first figures out that electrical connectivity has been established---at this point it knows something is plugged into the port.

Then (unless configured not to) the switch attempts to run autoneg to figure how how fast the link should run.

The source mac address of any traffic coming into the switch from the device will also get recorded in the switch's mac address table (which, is the list of what MAC addresses are out what ports).

When the router (IP layer) receives a packet for the IP the host owns,, the router will send out an ARP query on any interfaces on the relevant subnet to find the right MAC address for that IP. The ARP query hits the switch, which then floods out on all ports (on the relevant VLAN). Replies (which are transmitted by the device and thus recorded in the switch's MAC table), are transmitted back to the router, which records in it's MAC address table that the MAC for the given IP is out the port connected to the switch.

James Cape
  • 1,067
  • 8
  • 16
  • Good except that the recoeded MAC address is NOT sent to the router. The switch reports it'w own AMC on the port the router is connected to. ARP / MAC addressesa re only valid per ethernet segment, and a switch has a different segment on every port. – TomTom Feb 14 '11 at 12:30
  • I double-checked on a router-on-a-stick setup with a 2821 and a 2960 before answering. The arp table on the router includes the end device's mac address in the dotinterface, which means the arp requests are making it through the switch. – James Cape Feb 14 '11 at 13:57
  • @TomTom: That's not the case. The router will only discover the MAC address of the switch itself if: The switch is configured with an ip address, which it doesn't have to be, and if there is inbound traffic transiting the router destined for the ip address of the switch itself. The router works like any other network device in that it will ARP broadcast for the MAC address of any ip address it needs to forward traffic to. If you look at your router's MAC address table you should see entries for any devices connected to the switch that the router has forwarded traffic to. – joeqwerty Feb 14 '11 at 14:12