Scenario Context: You've logged into your Ubuntu-MGMT station and confirmed network connectivity. Now, you need to prepare the initial configurations for the switch (SW) and the router (R1). Before logging into them, it's a best practice to write and validate configurations offline. This lab teaches you how to use text editors in Linux to create and edit these critical files.
1. Create a structured directory for network configurations.
2. Learn the absolute basics of the nano text editor.
3. Learn the absolute basics of the vim text editor.
4. Use nano to create a VLAN configuration file for the core switch (SW).
5. Use vim to create an interface configuration file for the router (R1).
We're back in the Ubuntu-MGMT server. Once you logged (GUI) in to Ubuntu-MGMT station (Username: user and Password: Test123), open terminal and let's log to Linux server again.
ssh root@192.168.123.2
Enter the password root. You're at the root@kvm:~# prompt.
First, let's get organized. Having configuration files scattered in your home directory is messy and unprofessional. We need a dedicated place for network configurations. Let's create a directory. The mkdir command makes directories.
We'll create a directory called network-configs right inside our home directory (/root). We'll use the -p flag. This flag is powerful; it means "create parent directories if they don't exist." While we don't need it for this simple case, it's a good habit for more complex paths.
mkdir -p ~/network-configs
The ~ symbol, as we learned, is a shortcut for /root. So this command is identical to mkdir -p /root/network-configs. Press Enter.
Now, let's move into that new directory. Use the cd command, which stands for "change directory."
cd ~/network-configs
Press Enter. Your prompt should now change to root@kvm:~/network-configs#. Good. You're now in your working directory.
Let's list the contents with ls.
ls -la
It's empty, which is expected. We're about to fill it.
In the Linux world, you will constantly edit text files: scripts, configurations, logs. You cannot be a network automation engineer without mastering a text editor in the terminal. Today, we'll look at the two most common ones: nano and vim. Nano is simpler. Vim is more powerful but has a steeper learning curve. You need to know both because you'll encounter them everywhere.
Let's create our first file: the switch VLAN configuration. You are already in network-configs directory using command (cd ~/network-configs). We'll name it sw_vlan_config.txt. To create and open it with nano, you type nano followed by the filename.
nano sw_vlan_config.txt
Press Enter. The terminal screen clears, and you are now inside the nano editor. At the top, it says "GNU nano" and the filename. At the bottom, you see a list of commands like ^G Get Help. The ^ symbol means the Ctrl key. So ^G means press Ctrl+G.
The cursor is blinking at the top-left, ready for you to type. Let's write a very basic Cisco switch configuration. We'll create three VLANs: one for Management, one for Users, and one for Servers. Type the following lines exactly:
vlan 1
name DEFAULT
!
vlan 10
name VLAN_VPC1
!
vlan 20
name VLAN_VPC2
!
interface GigabitEthernet0/1
description TO-R1
switchport trunk encapsulation dot1q
switchport mode trunk
switchport trunk allowed vlan 1,10,20
!
interface range GigabitEthernet0/3
description ACCESS-PORTS
switchport mode access
switchport access vlan 10
!
interface GigabitEthernet1/0
description ACCESS-PORTS
switchport mode access
switchport access vlan 20
Great. Now, you need to save this file. Look at the bottom menu. It says ^O Write Out. That means press Ctrl+O to save ("Write Out"). Press Ctrl+O on your keyboard.
Nano will ask you for the "File Name to Write". It already shows sw_vlan_config.txt. Just press Enter to confirm. At the bottom, it will briefly show [ Wrote 53 lines ], confirming the save.
Now you want to exit nano and return to the terminal. The command is ^X Exit. Press Ctrl+X. You immediately drop back to your terminal prompt. You are no longer in the editor.
Let's verify the file was created and see its contents. Use the cat command, which concatenates and prints files.
cat sw_vlan_config.txt
Press Enter. You should see all the configuration lines you just typed printed to the screen. Perfect. You've just used nano to create a network configuration file.
Now, let's learn the very basics of vim. Vim has different modes. The two most important are Normal mode (for issuing commands) and Insert mode (for typing text). This can be confusing at first, but it's what makes vim fast.
We'll create the router configuration file: r1_interface_config.txt. You are already in network-configs directory using command (cd ~/network-configs). To open vim, type vim followed by the filename.
vim r1_interface_config.txt
Press Enter. The screen changes. You are now in vim's Normal mode. The screen might look empty, or it might have tildes (~) down the left side. These tildes represent lines that don't exist in the file yet.
You cannot start typing text yet. You must first enter Insert mode. Press the letter i on your keyboard. Look at the bottom-left of the screen. It should now say -- INSERT --. Good. You are now in Insert mode and can type.
Let's type a basic router configuration for R1's interfaces. Type the following:
interface GigabitEthernet1
no shutdown
!
interface GigabitEthernet1.1
encapsulation dot1Q 1 native
ip address 192.168.123.11 255.255.255.0
!
interface Loopback0
description loopback
ip address 1.1.1.1 255.255.255.0
no shutdown
!
ip route 0.0.0.0 0.0.0.0 192.168.123.1
Now, you need to save this file. To do anything in vim, you must go back to Normal mode. Press the Esc key on your keyboard. The -- INSERT -- text at the bottom disappears. You are now back in Normal mode.
To save the file, you type a command. Commands in vim start with a colon (:). To write (save) the file, first press ESC then command is :w. Type :w and press Enter. At the bottom left, you'll see "r1_interface_config.txt" 21L, 220C written. This confirms it saved 21 lines.
Now you want to exit vim. The command to quit is :q. Since you just saved, you can simply type :q and press Enter. If you try to quit without saving, vim will yell at you. To force quit without saving, you would use :q!.
Type :q and press Enter. You are back at the terminal prompt.
Let's verify this file as well.
cat r1_interface_config.txt
Press Enter. You should see your router configuration.
Let's do one more vim trick, because you will see it constantly. Let's view the switch file with vim, make a small change, and save it. Open the switch file in vim.
vim sw_vlan_config.txt
You are in Normal mode. Let's say you need to change VLAN 20's name from VLAN_VPC2 to CORP_USERS. First, you need to find the line. In Normal mode, you can search by typing / followed by the text. Type /VLAN_VPC2 and press Enter. Vim jumps the cursor to the word "VLAN_VPC2".
Now you need to edit it. Press i to enter Insert mode. Use the arrow keys to move the cursor just after the 2 in VLAN_VPC2. Press Backspace to delete VLAN_VPC2 and type CORP_USERS. Now, press Esc to go back to Normal mode.
Now save and quit in one command. The command is :wq (write and quit). Type :wq and press Enter.
Verify the change.
cat sw_vlan_config.txt | grep "name CORP"
The | is a pipe. It takes the output of the cat command and sends it to the grep command, which searches for the pattern "name CORP". You should see it now says name CORP_USERS.
Finally, let's see what you've created in your directory.
ls -l
You should see both files listed, with their sizes and creation times.
Summary: You've now created a dedicated workspace (~/network-configs) and used two critical Linux text editors to create device configurations. You know how to:
● In Nano: Open (nano filename), type, save (Ctrl+O), and exit (Ctrl+X).
● In Vim: Open (vim filename), enter Insert mode (i), type, exit Insert mode (Esc), save (:w), quit (:q), and save-and-quit (:wq).
These are the foundational skills for all future automation work. In the next lab, we'll organize these files properly and learn how to copy and manage them.