May 6, 2021

Juniper JunOS

Juniper makes lots of stuff, but are probably most widely known for their firewall products. Here we look at some basic management of the SRX line, which runs JunOS

hook to console

On the front of your SSG there will be a console connection, which usually fools you because it looks like a normal network port, but really it’s a serial connection that just LOOKS like a network port.

  1. you have to go find an adapter that will connect a CAT5 cable to a serial cable, sometimes you can find them in the Juniper box, but you can find them online for pretty cheap too
  2. On mine I had to then convert the serial connection to a USB, since my laptop only has USB, and no serial. I got a Tripplite one, which I think I found here I think for about $20. On Windows 7 I had to download the driver too from here, which I think is really for Windows 8, but it worked.
  3. you have to have a terminal program on your laptop that can talk over a serial connection. I used TeraTerm, which I downloaded from Sourceforge here
  4. Once I installed the driver and hooked up the USB -> serial -> CAT5 adapter -> CAT5 cable -> SSG console port, then I started TeraTerm with the following settings:
  5. COM3 (well, on mine it was just the next COM above the ones it used to show before I installed the Tripplite driver, which happened to be COM3), Baud rate: 9600, data 8 bit, parity: none, stop: 1 bit, flow control: none.
  6. if it worked and you’re connected, you should hit a couple times and it should give you a login: prompt.


SRX platform runs JunOS, which is a BSD, versus the old ScreenOS, so it’s a lot different.

When you boot the platform, it takes about 3 minutes to come up all the way, which seems like forever. Even after the interface lights come up it’s not done booting yet

You can use a Cisco style console cable, which is an RJ-45 ethernet looking cable on one end, and a serial 9-pin on the other end, which you plug into a USB -> Serial dongle, like a Tripp-Lite USA-19HS that you plug into your laptop. If you’re using a Mac do ls /dev/tty* and find something that looks like /dev/tty.USA19H141P1.1, that’s the console you want to connect to. Then do:

screen /dev/tty.USA19H141P1.1
login: root
switchname% cli
switchname> config
Entering configuration mode

Here are some common commands you’ll use. You’ll have to enter CLI mode to use them after you login. There’s also a web interface, which makes things easier to visualize.

command what it does
set system root-authentication plain-text-password sets the root password
show config shows your configuration
show system software Information for junos:
JUNOS Software Release [15.1X49-D45]
show int terse shows your interfaces
set protocols l2-learning global-mode switching changes to a layer 3 switch. You have to do this from the ‘configure’ mode.
commit saves your last commands, you probably should do a commit-check first if you want to check it first.
commit check tests your commands before you save them
commit confirmed 1 commit confirmed will be automatically rolled back in 1 minutes unless confirmed
delete interfaces ge-0/0/0 unit 0 family inet address removes that IP from that interface
request system reboot at now reboots the box immediately
set interfaces ge-0/0/0 unit 0 family inet address set the first interface to netmask

Set your previously transparent switch (L2) to a normal Layer 3 router:

#set protocols l2-learning global-mode switching
set system host-name whateveryouwanttocallyourfirewall
delete security zones security-zone BT interfaces ge-0/0/0
set security zones security-zone untrust
set security zones security-zone untrust interfaces ge-0/0/0
set security zones security-zone trust1
set interfaces ge-0/0/0 unit 0 family inet address
#set interfaces ge-0/0/0 unit 0 family ethernet-switching interface-mode access
rename interfaces ge--0/0/0.0 family inet to address

troubleshooting JunOS

You can watch stuff happen with some of these commands:

show security flow session destination-prefix
show security flow session protocol icmp
show security flow session summary
show security flow session nat
show security flow session nat interface ge-0/0/8.431
show security flow session nat destination-port 5001
show security flow session destination-prefix
set security zones security-zone untrust interfaces ge-0/0/0.0
show security flow statistics
show interfaces flow-statistics ge-0/0/1.0

Or record some session data and look at it later like:

set security flow traceoptions file 10debug
set security flow traceoptions flag basic-datapath
set security flow traceoptions packet-filter MatchTraffic source-prefix destination-prefix
tail -f /cf/var/log/10debug

Look for bad things. When you’re done, do:

edit security
deactivate flow traceoptions packet-filter MatchTraffic
deactivate flow traceoptions flag basic-datapath
show flow
traceoptions {
    file 10debug;
    inactive: flag basic-datapath;
    inactive: packet-filter MatchTraffic {

merging code

If you have a config file you change some stuff in with a text editor on your desktop, you can upload via the web interface, but if there are syntax errors it just quits and dumps the upload, rather than telling you what the issue is.

To get around this, you can cut/paste your code into the terminal with a command and it will tell you if there are issues and what they are. To do this:

  1. open up your config file you want to upload in a text editor like Notepad (or whatever)
  2. Select and copy all your text to the clipboard (Windows: ctrl-A then ctrl-C, Mac apple-A then apple-C)
  3. Connect to your Juniper with the console cable (plug the console cable to the unit, and the other end to your USB converter, then plug it into your laptop and run: screen /dev/tty.USA19H141P1.1 (on Mac))
  4. login then get into the cli, NOT THE EDIT MENU
  5. If you’re using iterm2 on Mac, Select Edit > Paste Special > Paste slow, this will allow the terminal paste to work better
  6. Now run this next command and then paste the contents of you clipboard
> test configuration terminal
paste your code now

Now it will tell you if there’s errors like:

terminal:3:(8) syntax error: test
  [edit system]
      syntax error
terminal:4:(11) statement must contain additional statements: ;
  [edit system login]
    'login ;'
      statement must contain additional statements
configuration syntax failed

You can use the “show” command to figure out where the issue is, then commit the code.

You can also get into the EDIT menu dump the config straight into there, but if it breaks, it might overwrite HALF of your config, or something weird, and give you a very strange config. If you decide to do it anyway, do:

load replace terminal

Reset root password

You have to reboot the unit and catch it with a console cable connected and watching the boot process in a terminal. After it boots for like a minute, you’ll get to a screen where you have to hit the SPACE bar to interrupt normal boot:

Consoles: U-Boot console
Found compatible API, ver. 2.5
FreeBSD/MIPS U-Boot bootstrap loader, Revision 2.5
(, Tue Apr  2 12:36:46 PDT 2013)
Memory: 2048MB
[0]Booting from internal-compact-flash slice 2
Un-Protected 1 sectors
writing to flash...
Protected 1 sectors
Loading /boot/defaults/loader.conf
/kernel data=0xb1618c+0x167c syms=[0x4+0x8bb00+0xcabc9]
Hit [Enter] to boot immediately, or space bar for command prompt.
Type '?' for a list of commands, 'help' for more detailed help.

Then type

loader> boot -s
Kernel entry at 0x801000e0 ...
init regular console
Primary ICache: Sets 64 Size 128 Asso 4
Primary DCache: Sets 1 Size 128 Asso 64
Secondary DCache: Sets 128 Size 128 Asso 8
GDB: debug ports: uart
GDB: current port: uart
Attaching /cf/packages/junos via /dev/mdctl...
Mounted junos package on /dev/md1...
OBooting single-user
Mounting /dev/bo0s3f /cf/var
** /dev/bo0s3f
clean, 299919 free (127 frags, 37474 blocks, 0.0% fragmentation)
System watchdog timer disabled
Enter full pathname of shell or 'recovery' for root password recovery or RETURN for /bin/sh: recovery

After you type recovery, it will enter a recovery shell eventually:

Performing system setup ...
Checking integrity of BSD labels:
  s1: Passed
  s2: Passed
  s3: Passed
  s4: Passed
** /dev/bo0s3e
clean, 23457 free (9 frags, 2931 blocks, 0.0% fragmentation)
** /dev/bo0s3f
Running recovery script ...
machdep.bootsuccess: 1 -> 1
Performing initialization of management services ...
Performing checkout of management services ...
NOTE: Once in the CLI, you will need to enter configuration mode using
NOTE: the 'configure' command to make any required changes. For example,
NOTE: to reset the root password, type:
NOTE:    configure
NOTE:    set system root-authentication plain-text-password
NOTE:    (enter the new password when asked)
NOTE:    commit
NOTE:    exit
NOTE:    exit
NOTE: When you exit the CLI, you will be asked if you want to reboot
NOTE: the system
Starting CLI ...

So it kind of tells you what to do, just enter the commands and type your new password and eventually reboot the system when it asks. If it worked, you can just watch it boot until you get to the normal login prompt like:

login: root

Different models have different processes to reset root, here’s a few:

EX-4550 juniper link

reset to factory defaults

If you do enough bad things, it’s sometimes easier to reset everything from the command line, here’s how you do that:

router> config
router# load factory-default
warning: activating factory configuration
router# set system root-authentication plain-text-password
New password:
Retype new password: 
router# commit

You should be able to hook up your laptop to one of the interfaces like 0/2 and get a dhcp lease and configure from web, or stick with cli and do it there.


SRX for beginners