\section{Routing}

\begin{frame}
   {Routing}

   \begin{itemize}
      \item Moving packets about and between networks
      \item Routing table
      \begin{itemize}
         \item Defines paths to all networks and hosts
         \item Local packets sent directly
         \item Remote traffic sent to routers
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{

   \textbf{Routing} is the process of selecting paths in a
   network along which to send network traffic. The
   \textbf{routing table} is a list of routes to other
   networks managed by the system. It defines paths to all
   networks and hosts, sending remote traffic to routers.

   To see the current routing table, one can use
   \textbf{route} or \textbf{ip}:

   \begin{figure}[H]
      \includegraphics[width=7in]{IMAGES/routeubuntu}
      \caption{Using route and ip route}
   \end{figure}

}


\begin{frame}
   {Default Route}

   \begin{itemize}
      \item Used when no routing table entry is matched
      \item Can be obtained dynamically using DHCP
      \item Can be manually configured (static)
      \begin{itemize}
         \item
         \textbf{Red Hat}-derived systems:
         \texttt{GATEWAY=x.x.x.x} in either\\
         \filelink{/etc/sysconfig/network} or\\
         \filelink{/etc/sysconfig/network-scripts/ifcfg-ethX}
         \item
         \textbf{Debian}-derived systems:
         \texttt{gateway=x.x.x.x} in\\
         \filelink{/etc/network/interfaces}
      \end{itemize}
      \item
      Can use \textbf{nmcli} to avoid modifying files in \filelink{/etc}
      by hand:
      \begin{cmd}
$ sudo  nmcli con mod virbr0 ipv4.routes 192.168.10.0/24 \
  +ipv4.gateway 192.168.122.0
$ sudo nmcli con up virbr0
      \end{cmd}


   \end{itemize}

\end{frame}

\cprotect\note{

   The \textbf{default route} is the way packets are sent
   when there is no other match in the routing table for
   reaching the specified network.

   You can set the default gateway at run time with:
   \begin{cmd}
$ sudo route add default gw 192.168.1.10 enp2s0
$ route
   \end{cmd}
   \begin{response}
Kernel IP routing table
Destination     Gateway       Genmask         Flags Metric Ref Use Iface
default         192.168.1.10  0.0.0.0         UG    0      0     0 enp2s0
default         192.168.1.1   0.0.0.0         UG    1024   0     0 enp2s0
172.16.132.0    0.0.0.0       255.255.255.0   U     0      0     0 vmnet1
192.168.1.0     0.0.0.0       255.255.255.0   U     0      0     0 enp2s0
192.168.113.0   0.0.0.0       255.255.255.0   U     0      0     0 vmnet8
   \end{response}

   Note this might wipe out your network connection!  You
   can restore either by resetting the network, or in the
   above example by doing:
   \begin{cmd}
$ sudo route add default gw 192.168.1.1 enp2s0
   \end{cmd}
   These changes are not persistent and will not survive a
   system restart.

}


\begin{frame}
   {Static Routes}

   \begin{itemize}
      \item Used to control packet flow when there is more than
      one router or route
      \item Defined per interface
      \item Can be persistent or non-persistent
      \item Using \textbf{ip} (non-persistent)
      \item Or persistently:
      \begin{itemize}
         \item \textbf{Red Hat}-based system:\\
         \filelink{/etc/sysconfig/network-scripts/route-ethX}

         \item \textbf{Debian}-based system:

         \filelink{/etc/network/interfaces}

         \item \textbf{SUSE}-based system:

         \filelink{/etc/sysconfig/network/ifroute-eth0}
      \end{itemize}
      \item
      Use \textbf{nmcli} to avoid changing files in \filelink{/etc} by hand
      (Exercise to follow)
   \end{itemize}

\end{frame}

\cprotect\note{

   When the system can access more than one route or
   router, or perhaps there are multiple interfaces, it is
   useful to selectively control which packets go to which.

   Either the \textbf{route} or \textbf{ip} command can be
   used to set a non-persistent route as in:
   \begin{cmd}
$ sudo ip route add 10.5.0.0/16 via 192.168.1.100
   \end{cmd}
   On a \textbf{Red Hat}-based system, a persistent route
   can be set by editing
   \filelink{/etc/sysconfig/network-scripts/route-ethX} as
   shown by:
   \begin{cmd}
$ cat /etc/sysconfig/network-scripts/route-eth0
  10.5.0.0/16 via 172.17.9.1
   \end{cmd}
   On a \textbf{Debian}-based system you need to add lines to
   \filelink{/etc/network/interfaces} such as:
   \begin{cmd}
iface eth1 inet dhcp
  post-up route add -host 10.1.2.51 eth1
  post-up route add -host 10.1.2.52 eth1
   \end{cmd}
   On a \textbf{SUSE}-based system you need to add to or create
   a file such as
   \filelink{/etc/sysconfig/network/ifroute-eth0} with lines
   like:
   \begin{cmd}
# Destination Gateway Netmask Interface [Type] [Options]
  192.168.1.150 192.168.1.1 255.255.255.255 eth0
  10.1.1.150 192.168.233.1.1 eth0
  10.1.1.0/24 192.168.1.1 - eth0
   \end{cmd}
   where each field is separated by tabs.

}



