> 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-basics/27-troubleshooting-with-traceoptions.md).

# 27) Troubleshooting with Traceoptions

### Pre-Work

Load the config called **broken.ospf.2.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename broken.ospf.2.cfg
```

### Lab

OSPF is setup, but the adjacency between R1 and R2 is not coming up. It is broken for a different reason than in the previous lab. Again, you are not allowed to look at the config of R2 for this lab.

Using traceoptions, identify the issue that is preventing OSPF from coming up. Fix the issue by only configuring R1.

### Answer

<details>

<summary>Expand to reveal</summary>

Configure `traceoptions` under OSPF:

```
set protocols ospf traceoptions file ospf-log.txt
set protocols ospf traceoptions flag hello
```

\
We could also use `flag all`, but `flag hello` will produce less output.

\
By viewing the file that is created, we can see that the issue is a mismatched netmask. R2 has a `/30` while R1 has a `/24`.

```
admin@R1> show log ospf-log.txt    
Jul 17 19:23:19 R1 clear-log[21361]: logfile cleared
Jul 17 19:23:24 trace_on: Tracing to "/var/log//ospf-log.txt" started
Jul 17 19:23:24.778517 OSPF sent Hello 10.1.2.1 -> 224.0.0.5 (ge-0/0/0.0 IFL 345 area 0.0.0.0)
Jul 17 19:23:24.778531   Version 2, length 48, ID 1.1.1.1, area 0.0.0.0
Jul 17 19:23:24.778536   mask 255.255.255.0, hello_ivl 10, opts 0x12, prio 128
Jul 17 19:23:24.778540   dead_ivl 40, DR 0.0.0.0, BDR 0.0.0.0
Jul 17 19:23:24.781192 OSPF sent Hello 10.1.2.1 -> 224.0.0.5 (ge-0/0/0.0 IFL 345 area 0.0.0.0)
Jul 17 19:23:24.781204   Version 2, length 48, ID 1.1.1.1, area 0.0.0.0
Jul 17 19:23:24.781209   mask 255.255.255.0, hello_ivl 10, opts 0x12, prio 128
Jul 17 19:23:24.781213   dead_ivl 40, DR 0.0.0.0, BDR 0.0.0.0
Jul 17 19:23:28.853352 OSPF rcvd Hello 10.1.2.2 -> 224.0.0.5 (ge-0/0/0.0 IFL 345 area 0.0.0.0)
Jul 17 19:23:28.853368   Version 2, length 44, ID 2.2.2.2, area 0.0.0.0
Jul 17 19:23:28.853372   checksum 0x0, authtype 0
Jul 17 19:23:28.853377   mask 255.255.255.252, hello_ivl 10, opts 0x12, prio 128
Jul 17 19:23:28.853382   dead_ivl 40, DR 0.0.0.0, BDR 0.0.0.0

```

\
We can set R1 to have the same mask:

```
edit interfaces ge-0/0/0.0 family inet
rename address 10.1.2.1/24 to address 10.1.2.1/30
```

\
OSPF should come up:

```
admin@R1> show ospf neighbor 
Address          Interface              State           ID               Pri  Dead
10.1.2.2         ge-0/0/0.0             Full            2.2.2.2          128    38

```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

Traceoptions are a very useful tool, which is similar IOS's debug, but much more powerful. Traceoptions can be configured anywhere in the hierarchy. You do not execute a trace from operational mode like you do in IOS. Instead, traceoptions are explicitly configured.

\
When you setup traceoptions, a log file is created. This allows you to safely capture debug output and store it in a file for later viewing. You don't have to watch the output on the CLI like you do with IOS's debug.

\
The flags control what information you capture. Using `flag all` is the easy way to ensure you are getting what you want, but often you can get what you want while capturing less output, for example using `flag hello` in this lab.

\
We can control the size and number of rotation files, just like we've seen previously with syslog:

```
admin@R1# set protocols ospf traceoptions file ?
Possible completions:
  <filename>           Name of file in which to write trace information
  files                Maximum number of trace files (2..1000)
  no-world-readable    Don't allow any user to read the log file
  size                 Maximum trace file size (10240..4294967295)
  world-readable       Allow any user to read the log file

```

\
Let's take a moment to dive deeper into `no-world-readable` vs `world-readable`. When `no-world-readable` is set, a user with class `operator` and below cannot view it:

```
user1@R1> show log ospf-log.txt 
error: could not open 'ospf-log.txt': Permission denied
```

\
But if we change to `world-readable`, they can. The default if nothing is configured is `no-world-readable`.

\
The underlying unix permission levels are changed with the `world-readable` command. You can see this using `file list /var/log detail`. Without `world-readable`:

```
-rw-r-----  1 root  root          68 Aug 9  11:11 ospf-log.txt
```

\
With `world-readable`:

```
-rw-r--r--  1 root  root          68 Aug 9  11:11 ospf-log.txt
```

\
Just like normal log files, we can use `clear log` to clear the contents of the file, and `show log` to view the contents of the file.

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/logical-system-security/topics/topic-map/flow-trace-for-logical-systems.html>

<https://networkdirection.net/articles/routingandswitching/juniper-routers-and-switches/juniper-traceoptions/>

<https://youtu.be/-DTKqW2iUH8?t=232>

<https://youtu.be/y3rGQtBfGi0?t=167>
