> For the complete documentation index, see [llms.txt](https://jncia-workbook.gitbook.io/workbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jncia-workbook.gitbook.io/workbook/junos-switching/1-basic-switching.md).

# 1) Basic Switching

### Pre-Work

Load the config called **lab1.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir switched-lan --config_filename lab1.cfg
```

### Lab

<figure><img src="/files/90MyisfqIY2VaI7h2qWT" alt=""><figcaption></figcaption></figure>

Configure SW2 and SW3 as follows:

* Configure two VLANs:
  * VLAN 100, name PROD
  * VLAN 200, name DEV
* The link between the switches, `ge-0/0/1`, should be a trunk port carrying both VLANs
* On both switches, `ge-0/0/2` should be assigned to VLAN 100, and `ge-0/0/3` should be assigned to VLAN 200

The simulated hosts host1-host3 should be able to ping each other within VLAN 100, as well as host2-host4 within VLAN 200.

```
admin@HOST-RTR> ping 10.0.100.103 routing-instance host1 count 2         
PING 10.0.100.103 (10.0.100.103): 56 data bytes
64 bytes from 10.0.100.103: icmp_seq=0 ttl=64 time=3.174 ms
64 bytes from 10.0.100.103: icmp_seq=1 ttl=64 time=3.893 ms

admin@HOST-RTR> ping 2001:db8:100::103 routing-instance host1 count 2    
PING6(56=40+8+8 bytes) 2001:db8:100::101 --> 2001:db8:100::103
16 bytes from 2001:db8:100::103, icmp_seq=0 hlim=64 time=3.065 ms
16 bytes from 2001:db8:100::103, icmp_seq=1 hlim=64 time=3.519 ms

admin@HOST-RTR> ping 10.0.200.104 routing-instance host2 count 2         
PING 10.0.200.104 (10.0.200.104): 56 data bytes
64 bytes from 10.0.200.104: icmp_seq=0 ttl=64 time=9.837 ms
64 bytes from 10.0.200.104: icmp_seq=1 ttl=64 time=4.354 ms

admin@HOST-RTR> ping 2001:db8:200::104 routing-instance host2 count 2    
PING6(56=40+8+8 bytes) 2001:db8:200::102 --> 2001:db8:200::104
16 bytes from 2001:db8:200::104, icmp_seq=0 hlim=64 time=263.428 ms
16 bytes from 2001:db8:200::104, icmp_seq=1 hlim=64 time=3.766 ms
```

### Answer

<details>

<summary>Expand to reveal</summary>

Configuration for both switches is the same:

```
set vlans PROD vlan-id 100
set vlans DEV vlan-id 200

set interfaces ge-0/0/1.0 family ethernet-switching interface-mode trunk 
set interfaces ge-0/0/1.0 family ethernet-switching vlan members [ PROD DEV ]  
set interfaces ge-0/0/2.0 family ethernet-switching interface-mode access
set interfaces ge-0/0/2.0 family ethernet-switching vlan members PROD
set interfaces ge-0/0/3.0 family ethernet-switching interface-mode access
set interfaces ge-0/0/3.0 family ethernet-switching vlan members DEV
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

We create VLANs using `set vlans <name> vlan-id <num>`

\
We assign access port using:

```
set interfaces ge-0/0/2.0 family ethernet-switching interface-mode access
set interfaces ge-0/0/2.0 family ethernet-switching vlan members <vlan name>
```

\
By default, a port with `family ethernet-switching` is an access port, so technically speaking we don't need this line:

```
set interfaces ge-0/0/2.0 family ethernet-switching interface-mode access
```

\
Another method for configuring access ports is assigning the interface under the VLAN config hierarchy, instead of directly under the interface config.

```
set vlans PROD interface ge-0/0/2.0
```

\
By default, all trunk ports carry no VLANs. We can use `members all`, or the more safe option, specifying each individual VLAN. Remember that in Junos, a list of values goes inside square braces with no comma separation.

```
set interfaces ge-0/0/1.0 family ethernet-switching vlan members [ PROD DEV ] 
```

\
Use `native-vlan-id` if you want to define the untagged VLAN on the trunk.

```
set interfaces ge-0/0/1.0 family ethernet-switching native-vlan-id <num>
```

* This does not appear to be available on vJunos-switch.

\
We can use `show vlans` to verify. The `*` next to an interface means the interface is up.

```
admin@SW2> show vlans 

Routing instance        VLAN name             Tag          Interfaces
default-switch          DEV                   200      
                                                           ge-0/0/1.0*
                                                           ge-0/0/3.0*
default-switch          PROD                  100      
                                                           ge-0/0/1.0*
                                                           ge-0/0/2.0*
default-switch          default               1        
```

\
Above, notice that `ge-0/0/1` is seen in both VLANs because it is a trunk port with both VLANs as members.

\
We can also use `show ethernet-switching interface` which more clearly provides separation between access and trunk ports.

```
admin@SW3> show ethernet-switching interface    
Logical Interface flags (DL - disable learning, AD - packet action drop,
                         LH - MAC limit hit, DN - interface down,
                         MMAS - Mac-move action shutdown,  AS - Autostate-exclude enabled,
                         SCTL - shutdown by Storm-control, SL - Secure Learning,
                         MI - MAC+IP limit hit, LP - Loop Protect Down,
                         MLAS - Mac limit action shutdown, CISO - Shutdown due to core isolation,
                         EMS - Shutdown due to evpn maintenance)

Routing         Logical         Vlan                   TAG   MAC    MAC+IP STP         Logical          Tagging
Instance        interface       members                      limit  limit  state       interface flags
default-switch  ge-0/0/1.0                                   524287 8192                                tagged   
default-switch                  DEV                    200   65535  1024   Forwarding                   tagged   
default-switch                  PROD                   100   65535  1024   Forwarding                   tagged   
default-switch  ge-0/0/2.0                                   524287 8192                                untagged 
default-switch                  PROD                   100   65535  1024   Forwarding                   untagged 
default-switch  ge-0/0/3.0                                   524287 8192                                untagged 
default-switch                  DEV                    200   65535  1024   Forwarding                   untagged 
```

\
We can use `show ethernet-switch` table to see the MAC table.

```
admin@SW3> show ethernet-switching table 

MAC flags (S - static MAC, D - dynamic MAC, L - locally learned, P - Persistent static, C - Control MAC
           SE - statistics enabled, NM - non configured MAC, R - remote PE MAC, O - ovsdb MAC
           GBP - group based policy, B - Blocked MAC)


Ethernet switching table : 4 entries, 4 learned
Routing instance : default-switch
    Vlan                MAC                 MAC         Age   GBP     Logical                NH        MAC        RTR
    name                address             flags             Tag     interface              Index     property   ID
    DEV                 aa:c1:ab:2d:bf:36   D             -           ge-0/0/1.0             0                    0       
    DEV                 aa:c1:ab:d8:57:57   D             -           ge-0/0/3.0             0                    0       
    PROD                aa:c1:ab:51:b4:6d   D             -           ge-0/0/1.0             0                    0       
    PROD                aa:c1:ab:d5:d9:3a   D             -           ge-0/0/2.0             0                    0      
```

</details>

### Further Reading

<http://notthenetwork.me/blog/2013/07/19/junos-basics-creating-vlans/>

<https://www.youtube.com/watch?v=k2F5-HE2JwM>

<https://www.youtube.com/watch?v=8vqMkfgb13A>
