Initial router configuration and static routes
In this chapter, you’ll learn how to configure Cisco routers.
Typically, the LAN-facing interface on a router connects to an Ethernet switch. That switch connects all of the endpoints (PCs, servers, printers, IP phones, and so on). The router’s LAN interface is configured with an IP address in the LAN’s network, and the endpoints in that LAN use that IP address as their default gateway.
For the WAN-facing interface, the router typically connects to another router. This interface must be configured with an IP address on a network that both routers share so they can exchange packets. That shared link uses a separate IP network from the LAN.
(Image 166)
Image Title - Two Routers connected to a WAN and their respective LANs with endpoints
Let’s walk through the configurations needed to get the routers operational. We’ll use the same configurations and protocols you learned throughout the IP connectivity section.
Initial router configuration
The initial configuration on a router is very similar to the initial configuration on an Ethernet switch (as covered in Chapter 2.5.1 Introduction to Cisco’s Internetworking Operating System (IOS)), because both devices run Cisco IOS.
When the router boots for the first time, it displays the Configuration Dialog prompt. You should cancel it by either typing the key combination “Ctrl+C” or typing “no” and pressing Enter.
After that, you’ll see the user EXEC prompt, which allows a limited set of {`show`} commands:
Router>
We need to enter privileged EXEC mode. Which command gets us there?
enable
Once you’re in privileged EXEC mode, you’ll see the prompt:
Router#
You can run more {`show`} commands here, but to change settings (like the hostname) you need global configuration mode. How do you enter global configuration mode?
configure terminal
Now that you’re in global configuration mode, which command changes the hostname to “R1”?
hostname R1
Next, we’ll configure the LAN-facing interface. Router interfaces (unlike switchports) are assigned an IP address in the same LAN as the endpoints, and that IP address becomes the hosts’ default gateway.
In this topology, the LAN-facing interface on R1 is GigabitEthernet0/0. We need to assign it an IP address in the 192.168.1.0/24 network. A common convention is to reserve the first usable IP address for the default gateway, so we’ll use 192.168.1.1.
To configure an interface, you first enter interface configuration mode:
interface gigabitethernet0/0
The prompt changes to:
Router(config-if)#
That tells you you’re configuring the GigabitEthernet0/0 interface. Now assign the IP address:
ip address 192.168.1.1 255.255.255.0
Notice that you must include the Subnet Mask in Dotted Decimal Notation after the IP address. This is mandatory.
While you’re still in interface configuration mode, there’s one more router-specific step:
All router interfaces are shutdown by default.
So, when you configure an interface in its default state, you must enable it with:
no shutdown
Similarly, if you want to disable a router interface, enter:
shutdown
within interface configuration mode for that interface.
Now that the LAN-facing interface is configured, verify it by returning to privileged EXEC mode (Ctrl+Z) and running:
show ip interface brief
(Image 167)
Image Title - Show ip interface brief command on R1
This command lists all router interfaces and the IP address assigned to each one.
- If an interface has no IP address configured, it shows as “unassigned”.
- The “Status” column tells you the administrative and physical state:
- “up” means the interface is enabled (you entered “no shutdown”).
- “administratively down” means the interface is disabled (default state or you entered “shutdown”).
- “down” usually means there’s no physical link (for example, no cable connected).
- The “Protocol” column shows whether the data-link layer is working:
- “up” means the remote end is connected and the remote interface is also up, so the local router can receive Layer 2 frames.
- “down” means the Layer 2 connection isn’t established.
To see the subnet mask configured on an interface, use {`show ip interface [interface name]`}. This also shows the interface status and other IP-related settings:
show ip interface gigabitethernet0/0
(Image 168)
Image Title - Show ip interface command on R1 showing the IP address and Subnet Mask configured on GigabitEthernet0/0
Once the interface is configured and shows “up/up”, the router should install a directly connected route for that network in its routing table. Verify with:
show ip route
(Image 169)
Image Title - Routing table on R1 showing directly connected route to 192.168.1.0/24
This means R1 is directly connected to the 192.168.1.0/24 network. If R1 receives a packet destined for an IP address in that network, it forwards the packet out of its GigabitEthernet0/0 interface.
Configuring static routes
Routes to remote networks often travel over a WAN (though not always). One of the simplest ways to reach a remote network you’re not directly connected to is to configure a static route.
To configure a static route, you must be in global configuration mode. The command has this structure:
| Command | Destination Network | Subnet Mask | Next Hop IP Address | Outgoing Interface (Optional) |
|---|
(Image 170)
Image Title - Two Routers connected to a WAN and their respective LANs
For example, suppose you want to configure a static route on R1 to reach the 192.168.4.0/24 network. If the next hop is 10.1.1.2 (the IP address of the GigabitEthernet0/1 interface on R2), the configuration looks like this:
| Command | Destination Network | Subnet Mask | Next Hop IP Address | Outgoing Interface (Optional) |
|---|---|---|---|---|
| ip route | 192.168.4.0 | 255.255.255.0 | 10.1.1.2 | GigabitEthernet0/1 |
You can optionally include the exit (outgoing) interface the router will use to send packets toward the destination (GigabitEthernet0/1 in this example). It’s not required. In our example, we’ll omit the outgoing interface:
ip route 192.168.4.0 255.255.255.0 10.1.1.2
(Image 171)
Image Title - Configuring a Static Route to the 192.168.4.0/24 network on R1
After you configure the route, you can view it in R1’s routing table with:
(Image 172)
Image Title - Viewing the contents of the R1’s Routing Table
You can also configure a static route using the outgoing interface instead of the next hop IP address. For example, this is also valid:
ip route 192.168.4.0 255.255.255.0 gigabitethernet0/1
You must specify at least one of the following:
- the next hop IP address
- the outgoing interface used to reach the next hop router You can also specify both.
It is important to note that the next-hop to the static route must be reachable in order for the static route to show up in your routing table. The next hop for the static route could either be a Directly Connected route, or learned from another route, but you must have a route to the next-hop within your routing table.