ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How Do I Add a Static Route in CentOS

    Water Closet
    linux centos route networking
    3
    12
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • hobbit666H
      hobbit666
      last edited by scottalanmiller

      How do I add a Static route to CentOS to a specific IP/Host but leave the reminder "network" as is?
      E.g. I want to ping a host on 192.168.16.254 via a router on 10.0.1.242 BUT the rest of the network needs to ping via 10.0.1.220 (which is the default gateway on the server)

      DashrenderD 1 Reply Last reply Reply Quote 1
      • DashrenderD
        Dashrender @hobbit666
        last edited by Dashrender

        @hobbit666 said in Random Thread - Anything Goes:

        How do I add a Static route to CentOS to a specific IP/Host but leave the reminder "network" as is?
        E.g. I want to ping a host on 192.168.16.254 via a router on 10.0.1.242 BUT the rest of the network needs to ping via 10.0.1.220 (which is the default gateway on the server)

        ip route add 192.168.16.254/32 via 10.0.1.242 dev eth0

        You might be able to drop the /32 because you've already specified an exact host, but I'm not sure on Linux routing command.

        scottalanmillerS 1 Reply Last reply Reply Quote 1
        • scottalanmillerS
          scottalanmiller @Dashrender
          last edited by

          @dashrender said in Random Thread - Anything Goes:

          @hobbit666 said in Random Thread - Anything Goes:

          How do I add a Static route to CentOS to a specific IP/Host but leave the reminder "network" as is?
          E.g. I want to ping a host on 192.168.16.254 via a router on 10.0.1.242 BUT the rest of the network needs to ping via 10.0.1.220 (which is the default gateway on the server)

          ip route add 192.168.16.254/32 via 10.0.1.242 dev eth0

          You might be able to drop the /32 because you've already specified an exact host, but I'm not sure on Linux routing command.

          You can definitely skip the connection info, unless for some reason it is not implied.

          1 Reply Last reply Reply Quote 0
          • hobbit666H
            hobbit666
            last edited by

            Just keep getting this
            RTNETLINK answers: Network is unreachable

            1 Reply Last reply Reply Quote 0
            • hobbit666H
              hobbit666
              last edited by

              Ah I can't do it as the router is on a different IP to the CentOS machine ๐Ÿ˜ž

              scottalanmillerS 1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller @hobbit666
                last edited by

                @hobbit666 said in How Do I Add a Static Route in CentOS:

                Ah I can't do it as the router is on a different IP to the CentOS machine ๐Ÿ˜ž

                What do you mean?

                1 Reply Last reply Reply Quote 0
                • hobbit666H
                  hobbit666
                  last edited by hobbit666

                  Should of made my 1st post a bit clearer.

                  Server is on a VLAN 172.20.0.0/24 (CentOS Machine 172.20.0.212) with a default gateway of 172.20.0.220 (Cisco Core switch - Also 10.0.1.220 on VLAN1)

                  So all traffic goes to the Cisco switch and that routes to the gateway needed either the MPLS or a Draytek.

                  What I needed was the keep traffic going to 10.0.2.1 - 10.0.2.253 going through the default Core route,
                  But
                  10.0.2.254 going through the Draytek on 10.0.1.242. But as it's a different IP I get the error.

                  So maybe I need to add the 172.20. VLAN as a 2nd LAN connection on the Draytek or give the CentOS machine a 2nd NIC on the VLAN1 network.

                  1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller
                    last edited by

                    You can only route to your immediate router.

                    1 Reply Last reply Reply Quote 2
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      Your roting logic has to be at the point o fhte route, not earlier.

                      1 Reply Last reply Reply Quote 1
                      • hobbit666H
                        hobbit666
                        last edited by

                        Got this working now by adding an adaptor to the VM on the VLAN1 network and doing some stuff with route and rules on the config of each adaptor in CentOS7

                        1 Reply Last reply Reply Quote 0
                        • DashrenderD
                          Dashrender
                          last edited by

                          Did you only get any of his one VM affected?

                          If so, Iโ€™ll his solution is good. But if you donโ€™t anted this for anyone looking for that network, you should add a command to the default router on the subnet in question

                          hobbit666H 1 Reply Last reply Reply Quote 0
                          • hobbit666H
                            hobbit666 @Dashrender
                            last edited by

                            @dashrender
                            It's a one off issue we have. We have all 50+ Sites running of an MPLS, if something happens and we need BT to look at a line issue then we are subject to OpenReach SLA's. So while they are down most stores have monitored CCTV on a separate BB line, so we use this as a temp VPN connection to a Draytek here that is on a different sub net range to my VM infrastructure. So when they are using the VPN and the route has been changed on the Core switch zabbix can't ping the MPLS Cisco router as the route now goes through the Draytek. So I need to static the route through the MPLS router so zabbix tells me the connection is up once BT have visited.

                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post