Basic configuration of juniper device
<yambe:breadcrumb>Switch_configuration_notes|Switch configuration</yambe:breadcrumb>
Basic configuration of juniper device
Juniper has very useful beginner tutorials at https://www.juniper.net/dayone in form of "Day One" series. Readers are encouraged to refer to them (esp "Exploring Junos CLI" and "Configuring Junos Basics") so that they are comfortable with material presented in this page.
Basic system configuration
A sample system configuration is:
system { host-name JUN1-DEP1; domain-name virtual.sbarjatiya.com; domain-search [ virtual.sbarjatiya.com example.com ]; location { country-code 0091; building Building-X; floor 2; } root-authentication { encrypted-password "<encrypted password>"; ## SECRET-DATA } name-server { 10.4.3.222; } login { announcement "Welcome to Department1 Juniper switch"; message "Unauthorized access is prohibited"; user saurabh { full-name "Saurabh Barjatiya"; uid 501; class super-user; authentication { encrypted-password "<encrypted password>"; ## SECRET-DATA } } } services { ssh { root-login allow; } telnet; web-management { http; } } syslog { user * { any emergency; } file messages { any notice; authorization info; } file interactive-commands { interactive-commands any; } } ntp { boot-server time.google.com; server 10.4.8.3; } }
This configuration has following information:
- System host-name, domain-name and search domains
- Switch location
- Root password
- DNS server(s)
- Login announcement and message
- System users with their privilege level and UID
- SSH, telnet and http services are enabled. Root login is enabled over SSH
- Following syslog configuration is achieved
- Message from any facility of level emergency or above will be sent to all logged in users on their terminals
- All messages from any facility of level notice or above will be logged to file named messages. Since syslog files are stored in /var/log, file /var/log/messages would receive all these messages.
- All commands typed interactively (console, SSH) will get stored in file interactive-commands.
- Switch will use ntp-server time.google.com at boot to synchronize time and will use ntp server at 10.4.8.3 to regularly synchronize time while running
Creating VLANs
To create an L2 VLAN use:
vlans { Management { vlan-id 2; interface { ge-0/0/0.0; ge-0/0/1.0; ge-0/0/2.0; ge-0/0/3.0; } } }
This would create a L2-VLAN named Management with four member ports.
To give switch an L3 IP address for the VLAN use:
interfaces { vlan { unit 0 { family inet { address 10.4.15.5/22; } } } } [edit vlans Management] l3-interface vlan.0;
to create a L3-VLAN named vlan.0 with switch's IP address 10.4.15.5 and to associate this L3-VLAN with Management vlan.
Configure static routes
A sample configuration which uses static routes is:
routing-options { static { route 0.0.0.0/0 next-hop 10.4.12.1; route 192.168.36.0/25 next-hop 10.4.12.1; } }
Configure access ports
To configure access port use:
interfaces { ge-0/0/0 { unit 0 { family ethernet-switching { port-mode access; vlan { members VLAN_NODE; } } } } ... } ... vlans { VLAN_NODE { vlan-id 5; } ... }
Configure storm control
To configure storm-control on all ports use:
ethernet-switching-options { storm-control { interface all; } }
Configure trunk port
To configure trunk port with native-vlan (PVID) 2 and associate a L3-VLAN (vlan.1) with it use:
interfaces { ... ge-0/0/23 { unit 0 { family ethernet-switching { port-mode trunk; vlan { members all; } native-vlan-id 2; } } } ... vlan { unit 1 { family inet { address 10.4.4.103/23; } } } } vlans { VLAN_NODE { vlan-id 5; } vlan2 { vlan-id 2; l3-interface vlan.1; } vlan800 { vlan-id 800; } }
Useful commands
A table containing list of useful operational mode juniper commands is:
Command | Description |
show system uptime | To see current time and system uptime |
configure | Enter configuration mode |
configure private | Enter configuration mode where changes done by other users are not visible and similarly changes done are not visible to other users |
configure exclusive | Enter configuration mode so that only current user can configure the device to avoid race conditions among various administrators |
file list, file show, file copy | Work with various files from cli. A simpler way could be to ssh to device and use shell |
telnet, ssh, ping, traceroute | Use telnet, ssh, ping or traceroute clients |
start shell | Start a shell inside cli |
monitor start messages | To display messages sent to messages file on console. |
monitor list | Obtain ist of channels being monitored |
monitor stop messages | To stop monitoring messages file on console |
show host | Resolve hostname to IP address using configured DNS |
set date | Set system date and time manually or using ntp |
show ntp {associations, status} | To see ntp association or status information |
show chasis hardware | See information about various slots, PICs and ports available on current switch |
show log messages | To see messages log channel |
last 30 | To see last 30 messages sent to messages channel |
show system connections | Show current network connection status, similar to netstat |
A table containing list of useful configuration mode juniper commands is:
Command | Description |
annotate | Leave comments about a configuration statement |
show | See current candidate configuration |
compare | Compare candidate configuration with running configuration (ie rollback 0 configuration) |
display set | Display current configuration in terms of set commands |
display detail | Display more detailed information about configuration |
display xml | Show configuration in XML format |
commit | Commit candidate configuration as running configuration |
commit at | Commit candidate configuration as running configuration at given time |
commit confirmed | Commit configuration and wait for confirmation within next specified number of minutes. If the new configuration is not confirmed thorough another 'commit' command the automatically rollback to previous configuration when time is over |
commit check | Check configuration through various commit scripts and tests to verify whether it passes various commit checks |
edit, set, delete, rename, copy, activate, deactivate | Change various configuration values |
rollback | Restore previous configuration using number. Up to last 49 configuration can be restored using rollback |
run | Run operational mode command from configuration mode |
top, up, exit | Move around while editing configuration |
Miscellaneous issues
Using out-of-band management interface on EX series switches
EX series switches come with out of band management interface which can be used using:
set interfaces me0 unit 0 family inet address 172.26.27.44/24
Note for various other devices management interface is called fxp0
Configure host for syslog
To send syslog messages to a host instead of regular file or user console use:
set system syslog host loghost any notice
In such cases special prefix can be attached to log messages to indicate that they originated from current device using:
set system syslog host loghost log-prefix JUNOS
Further messages can be configured to have facility and level information using:
set explicit-priority
configuration option when within [edit system syslog host] or [edit system syslog file]
Finally to send messages with custom facility name to help with separation of logs from multiple devices on log server use:
set facility-override local7