Configure the Ip Address and Default Gateway of Your Switch

In this article I will show you how to configure an Ip address and a default gateway in your manageable switch.

But first things first,

Why is an Ip address and default gateway needed in the switch?

After all switches are OSI Layer 2 devices that care only about MAC addresses.

The modern switches are manageable and support extra features than normal old fashion switches. This features include the support of TCP/IP applications like ping, telnet, trace route etc. For example, if you want to telnet or ping a switch, the switch must have an Ip configured. Also, if you want to execute ping or telnet to a device in another subnet the switch must have a default gateway configured.

Now let’s see the configuration for a 2950 series cisco switch.

Ip address

To configure the ip address first you have to enter from global configuration mode to interface vlan 1.

Switch#

Switch#conf t

Switch(config)#int vlan 1

Switch(config-if)#ip address {your ip address} {mask}

Switch(config-if)#no shutdown

Default Gateway

Be careful!!! The configuration of default gateway takes place in the configuration mode and the command does not include the mask for the ip.

Switch#

Switch#conf t

Switch(config)#ip default-gateway {ip address}

Now you can access your switch remotely, you can ping it from another network with different subnet and start “playing” with the settings. Have fun

25 thoughts on “Configure the Ip Address and Default Gateway of Your Switch

  1. So, How would we check the status of the default gateway that was configured on the switch?

  2. If i have more than one VLAN configured on the switch, what would be the default-gateway i configure on the switch ??? (each VLAN is in a different subnet …. )

  3. I don’t know much about configuration but if i can have more of the configuration process about hub, routers and swithes i’ll be very happy i’ll get back to you people thanks verymuch i’m waiting for more example on how to do it once more i’m really happy.

  4. why do we configure the default gateway on switch??.we configured gateway on PC.

    As L2 switch does not understand the Ip address?

  5. @ Niranjan. the command to check the ip on switch is, from the global configuration mode type show run. i.e. switch(cinfig)#show run

  6. Satyendra says:
    February 11, 2010 at 8:06 pm :

    “why do we configure the default gateway on switch??.we configured gateway on PC.

    As L2 switch does not understand the Ip address?”

    Answer : it is for management purposes and does not affect user traffic. What if you’d logon to a switch and ping or telnet from there? (this is common). The switch would not know what to do with it if it did not know a default gateway / router.

  7. and what about layer 3 switch

    vlan 1 – management purpose

    default gateway – to route another network

    is it right?

  8. 10X very helpful.

    pls could one help me on how to telnet into a switch.Also what information do i need to log into a device and view the log file in it.10x as you reply.

  9. Understanding Vlans and gateway setup is not as bad as you think.

    Let say we have one router that is connected to a switch and on that switch we have two Pc’s connected. Will call them pc 1 and pc2.
    now, on pc1 my config is as follows; Ip address=:192.168.10.1, mask 255.255.255.0 and my gateway = 192.168.30.254

    On pc2 we have ip address:192.168.20.1, mask 255.255.255.0 and the ip for gateway = 192.168.30.254

    on my switch I need to configure and Ip address for Vlan 1 which is for managing the switch remotely.
    I also need to configure an default ip address on the switch, which will be The ip address that you have configured for the interface going out the router to switch, let say we call it fa0/0 and this will be 192.168.30.254
    Your ip address for that router will be in the same range as the 192.168.30–Network address and the last octet will be the host.
    so let say we will have the ip address set on the switch as follows:
    192.168.30.3

    My two Vlans subinterfaces on the router have the following ip addresses:Fa0/0.10 = 192.168.10.254 and the mask =255.255.255.0
    Fa0/0/20 = 192.168.20.254 and the mask = 255.255.255.0

    Fa0/0 = 192.168.30.254 and mask = 255.255.255.0
    This Fastethernet interface is also the gateway ip address that you must configure for pc 1 and pc 2 and also as the default gateway ip address for the switch.

    If you set it up you can route between your vlans.
    If you want to telnet from any pc to your switch you can but you must set up your line console 0, password “passwordname”, login

    You also need to set up you line vty 0 4 with password and login.
    You can also have an enable secret password set up in your global command.

    If you set these lines up on your router as well and give your router a different password for example cisco on router and switch1 as password on your switch.
    If you do this lab and configure it right you can telnet from pc going into the switch and then telnet going into the router and that is pretty cool if you can do that . Good Luck……..!

  10. i get it, what you said about this george, but somehow i have difficulties in assessing things such as native vlan.. coz i know to have a common language for a 2 pc’s with diff vlan, you have to set a native vlan and in setting native vlan in the main switched you have to set an ip for that native vlan and the gateway. but how is it that my professor was asking me to assign the first host ip add from one particular vlan and its default gateway which is not the native vlan in the network.hows that possible the two pc’s with diff vlan will be able to communicate?

  11. This tutorial is great, I was searching this on internet but could not find such precise and to the point information.
    Thanks again!!

  12. Hi to all i’ll try to this procedure to set ip default gateway but not successful “invalid input detected at marker” can you help me to this error please