Switching

last person joined: 3 days ago 

Ask questions and share experiences about EX and QFX portfolios and all switching solutions across your data center, campus, and branch locations.
Expand all | Collapse all

Finding port IP address

  • 1.  Finding port IP address

    Posted 06-05-2010 10:53

    I need a simple, quick way to find what IP address is on a port.

     

    '>show arp' gives me:

     

    MAC Address       Address         Name                      Interface           Flags
    00:01:00:fa:aa:11 10.1.5.34       10.1.5.34                 vlan.5              none

    Yes, interface vlan.5, but I need to see Interface ge-2/0/5, has IP 10.1.5.34, or Interface ge-6/0/11 has IP 10.1.5.22.  There are hundreds of ports in the virtual chassis in interface vlan.5 so really show arp is not the command I need.

     

    there is no DHCP, so '>show dhcp snooping bindings' does not return any results. 

     

    Thanks!

    Gerry

     

     



  • 2.  RE: Finding port IP address

    Posted 06-05-2010 11:26

     

     I, too, wish there was a single command to show you the interface (Juniper - are you listening?). That said, it can be done in two steps and I do it all the time tracking down hosts.

     

    Do the show arp you mentioned - quickest if it's like:

     

    show arp | match 10.1.5.34

     

    If there is no match, then ping the IP and try again (even if pings are not returned - ARP resolution will take place if the host is alive).

     

    Then, to find the interface, do a:

     

    show ethernet-switching-table | match 00:01:00:fa:aa:11

     

    That should return the specific interface. 

     

    So, show ARP matching on IP to find MAC, then show switching table list matching on MAC. 

     

    Again, I'd LOVE for Juniper to create a single command for doing this in one step using only the IP. Granted, if there is no layer 3 routing the switch is engaged in covering those IPs, there won't be ARP resolution.

     

    Hope that helps!

     - Aaron

    Director of Network Services

    Sweet Briar College

    Sweet Briar, Va

     



  • 3.  RE: Finding port IP address

    Posted 06-08-2010 07:16

    Hi,

     

    If you wish I can write an OP Script for you which would show all learned IP addresses on specific phy port. You would be able to call it from CLI like "op show-all-ips ge-0/0/0". Should I?

     

    Kind Regards

    Michael Pergament



  • 4.  RE: Finding port IP address

    Posted 06-08-2010 07:22

     

     I would really love that if you do, in fact, have time to do that. I've considered writing scripts but haven't had the time to delve into it yet, so I'd appreciate this both for the functionality and as a working example for future scripts.

     

    Very generous of you and much appreciated! 🙂

     - Aaron

     



  • 5.  RE: Finding port IP address
    Best Answer

    Posted 06-08-2010 08:23

    Hi,

     

    please try attached script.  Copy this script under /var/db/scripts/op/.

     

    lab@Core-080-012-BACKROW# show system scripts
    op {
        file show-if-ips.slax;
    }

     

    lab@Core-080-012-BACKROW# run op show-if-ips interface ge-0/0/4
    Learned IP is 172.30.80.6 with MAC address 00:10:db:55:db:6d
    Learned IP is 172.30.80.5 with MAC address 00:10:db:ff:26:d0
    Learned IP is 172.30.80.28 with MAC address 00:10:db:ff:26:d0
    Learned IP is 172.30.80.30 with MAC address 00:10:db:ff:26:d0

     

    P.S. I need to optimize it so just let me know if a general functionality is ok for you.

     

    Kind Regards

    Michael Pergament

     

    If this worked for you please flag my post as an "Accepted Solution" so others can benefit. A kudo would be cool if you think I earned it.



  • 6.  RE: Finding port IP address

    Posted 06-08-2010 08:34

     

     OK, definitely giving this a whirl. 

     

     I've dropped it in /var/db/scripts/op 

     

     but I don't get the result you have for 'show system scripts'. Am I missing a setting that is not enabled by default that precedes this functionality? Also, I'm on 9.5S1.2 on this particular switch at the moment. 

     

    Thanks!

     - aaron

     



  • 7.  RE: Finding port IP address

    Posted 06-08-2010 08:35

     

     Nevermind! 🙂 I poked around a bit and found how I declare the script properly... testing it now.

     

     - Aaron

     



  • 8.  RE: Finding port IP address

    Posted 06-08-2010 08:42

     

     Yep! Works like a charm and just as you described. This is going to be a huge time saver that I'm going to push out to key switches across campus for future use.

     

     Thanks for the script and such a quick turnaround. I've marked Kudos on your post but don't see where I can mark this as an accepted solution. Maybe only the original poster can do that?

     

    Thanks!

     - Aaron

     



  • 9.  RE: Finding port IP address

    Posted 06-08-2010 09:01

    I optimized the script to get only MAC entries for specific interface instead of parsing all entries. Just take an updated version from my previous message.

     

    Kind Regards

    Michael Pergament



  • 10.  RE: Finding port IP address

    Posted 08-13-2010 19:57

    Dear All,

     

    I am using SRX 100 and copied the slax in the /cf/var/db/scripts/op, but with the following result:

     

    > op show-if-ips detail

    2010-08-14 02:56:07 UTC: running op script 'show-if-ips.slax'
    2010-08-14 02:56:07 UTC: opening op script '/var/db/scripts/op/show-if-ips.slax'
    2010-08-14 02:56:07 UTC: reading op script 'show-if-ips.slax'
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.
    2010-08-14 02:56:09 UTC: inspecting op output 'show-if-ips.slax'
    2010-08-14 02:56:09 UTC: finished op script 'show-if-ips.slax'

    Any hints?

     

    Thanks in advance.

    Br,

    Sam



  • 11.  RE: Finding port IP address

    Posted 08-15-2010 08:27

    Hello,

     

     


    @fwpsam wrote:

    Dear All,

     

    I am using SRX 100 and copied the slax in the /cf/var/db/scripts/op, but with the following result:

     

    > op show-if-ips detail


     

    This script has to be invoked as below:

     

     

    op show-if-ips interface <interface-name>

     http://forums.juniper.net/t5/Ethernet-Switching/Finding-port-IP-address/m-p/42600#M2136

     

     

    You have invoked it without keyword "interface" and did not give interface-name.

    Please retry with correct syntax.

    HTH

    Rgds

    Alex

     



  • 12.  RE: Finding port IP address

    Posted 08-18-2010 02:59

    Dear Alex,

     

    I have tried with the interface value, but still get error:

     

    {master:0}
    root@test> op show-if-ips detail interface ge-0/0/0
    2010-06-24 07:52:46 UTC: running op script 'show-if-ips.slax'
    2010-06-24 07:52:46 UTC: opening op script '/var/db/scripts/op/show-if-ips.slax'
    2010-06-24 07:52:46 UTC: reading op script 'show-if-ips.slax'
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.
    2010-06-24 07:52:47 UTC: inspecting op output 'show-if-ips.slax'
    2010-06-24 07:52:47 UTC: finished op script 'show-if-ips.slax'

     

    Thanks.

    Br,

    Sam



  • 13.  RE: Finding port IP address

    Posted 08-18-2010 03:16

    Hi,

     

    please skip "detail":

     

    root@test> op show-if-ips interface ge-0/0/0

     

    If you still see same message (this what I expect) then please attach following outputs:

    lab@Core-080-012-BACKROW# run show arp | display xml

    lab@Core-080-012-BACKROW# run show ethernet-switching interfaces ge-0/0/0 | display xml

     

    Thanks!

    Michael



  • 14.  RE: Finding port IP address

    Posted 08-18-2010 03:26

    Dear Michael,

     

    Please find the following output:

     

    root@test> op show-if-ips  interface ge-0/0/0
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.

     

    root@test> show arp | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/9.6R1/junos">
        <arp-table-information xmlns="http://xml.juniper.net/junos/9.6R1/junos-arp" junos:style="normal">
            <arp-table-entry>
                <mac-address>00:23:26:8c:0a:26</mac-address>
                <ip-address>192.168.1.2</ip-address>
                <hostname>192.168.1.2</hostname>
                <interface-name>vlan.1</interface-name>
                <arp-table-entry-flags>
                    <none/>
                </arp-table-entry-flags>
            </arp-table-entry>
        </arp-table-information>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>


    root@test> show ethernet-switching interfaces ge-0/0/0 | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/9.6R1/junos">
        <switching-interface-information xmlns="http://xml.juniper.net/junos/9.6R1/junos-esw" junos:style="brief">
            <interface>
                <interface-name>ge-0/0/0.0</interface-name>
                <interface-state>up</interface-state>
                <interface-vlan-member-list>
                    <interface-vlan-member>
                        <interface-vlan-name>vlan1</interface-vlan-name>
                        <interface-vlan-member-tagid>1</interface-vlan-member-tagid>
                        <interface-vlan-member-tagness>untagged</interface-vlan-member-tagness>
                        <interface-msti-id>0</interface-msti-id>
                        <blocking-status junos:emit="emit">unblocked</blocking-status>
                    </interface-vlan-member>
                </interface-vlan-member-list>
            </interface>
        </switching-interface-information>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>

     

    Thanks.

    Br,

    Sam



  • 15.  RE: Finding port IP address

    Posted 08-18-2010 04:13

    Hi,

     

    sorry and this one:

    show ethernet-switching table interface ge-0/0/0 | display xml

     

    Could it be that you have a corrupted version of script?

     

    Thanks!

    Michael



  • 16.  RE: Finding port IP address

    Posted 08-18-2010 05:58

    Dear Michael,

     

    I used another SRX100 for testing, please find the following recapture logging:

     

    root# run op show-if-ips interface fe-0/0/4
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.

    root# run show arp | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.1R2/junos">
        <arp-table-information xmlns="http://xml.juniper.net/junos/10.1R2/junos-arp" junos:style="normal">
            <arp-table-entry>
                <mac-address>00:23:26:8c:0a:26</mac-address>
                <ip-address>192.168.4.2</ip-address>
                <hostname>192.168.4.2</hostname>
                <interface-name>vlan.4</interface-name>
                <arp-table-entry-flags>
                    <none/>
                </arp-table-entry-flags>
            </arp-table-entry>
        </arp-table-information>
        <cli>
            <banner>[edit]</banner>
        </cli>
    </rpc-reply>

     

    root# run show ethernet-switching interfaces ge-0/0/4 | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.1R2/junos">
        <switching-interface-information xmlns="http://xml.juniper.net/junos/10.1R2/junos-esw" junos:style="brief">
        </switching-interface-information>
        <cli>
            <banner>[edit]</banner>
        </cli>
    </rpc-reply>

    root#show ethernet-switching table interface ge-0/0/4 | display xml

    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.1R2/junos">
        <xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
            <source-daemon>ethernet-switching</source-daemon>
            <message>Family ethernet-switching not configured on ge-0/0/4.0</message>
        </xnm:error>
        <cli>
            <banner>[edit]</banner>
        </cli>
    </rpc-reply>

     

     Pls also find the attached slax file.

     

    Thanks.

    Br,

    Sam



  • 17.  RE: Finding port IP address

    Posted 08-19-2010 05:22

    Hi,

     

    it seems that inteface ge-0/0/4 has not family ethernet-switching configured. That must be the reason why script fails.

     

    Kind Regards

    Michael Pergament



  • 18.  RE: Finding port IP address

    Posted 08-19-2010 20:03
      |   view attached

    Dear Michael,

     

    Thanks.

     

    Please find the following capture on my ex4200 again. Also the configuration and slax attached.

     

    {master:0}[edit interfaces vlan]
    root@test# run op show-if-ips interface ge-0/0/4.0
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.

     

    root@test# run show arp | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/9.6R1/junos">
        <arp-table-information xmlns="http://xml.juniper.net/junos/9.6R1/junos-arp" junos:style="normal">
            <arp-table-entry>
                <mac-address>00:23:26:8c:0a:26</mac-address>
                <ip-address>192.168.1.2</ip-address>
                <hostname>192.168.1.2</hostname>
                <interface-name>vlan.1</interface-name>
                <arp-table-entry-flags>
                    <none/>
                </arp-table-entry-flags>
            </arp-table-entry>
        </arp-table-information>
        <cli>
            <banner>{master:0}[edit]</banner>
        </cli>
    </rpc-reply>


    root@test# run show ethernet-switching interfaces ge-0/0/4 | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/9.6R1/junos">
        <switching-interface-information xmlns="http://xml.juniper.net/junos/9.6R1/junos-esw" junos:style="brief">
            <interface>
                <interface-name>ge-0/0/4.0</interface-name>
                <interface-state>up</interface-state>
                <interface-vlan-member-list>
                    <interface-vlan-member>
                        <interface-vlan-name>vlan1</interface-vlan-name>
                        <interface-vlan-member-tagid>1</interface-vlan-member-tagid>
                        <interface-vlan-member-tagness>untagged</interface-vlan-member-tagness>
                        <interface-msti-id>0</interface-msti-id>
                        <blocking-status junos:emit="emit">unblocked</blocking-status>
                    </interface-vlan-member>
                </interface-vlan-member-list>
            </interface>
        </switching-interface-information>
        <cli>
            <banner>{master:0}[edit interfaces vlan]</banner>
        </cli>
    </rpc-reply>


    root@test# run show ethernet-switching table interface ge-0/0/4 | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/9.6R1/junos">
        <ethernet-switching-table-information xmlns="http://xml.juniper.net/junos/9.6R1/junos-esw" junos:style="brief">
            <ethernet-switching-table junos:style="brief">
                <mac-table-count>1 unicast entries</mac-table-count>
                <mac-table-entry junos:style="brief">
                    <mac-vlan>vlan1</mac-vlan>
                    <mac-address>*</mac-address>
                    <mac-type>Flood</mac-type>
                    <mac-age>-</mac-age>
                    <mac-interfaces-list>
                        <mac-interfaces>All-members</mac-interfaces>
                    </mac-interfaces-list>
                </mac-table-entry>
                <mac-table-entry junos:style="brief">
                    <mac-vlan>vlan1</mac-vlan>
                    <mac-address>00:23:26:8c:0a:26</mac-address>
                    <mac-type>Learn</mac-type>
                    <mac-age junos:seconds="0">0</mac-age>
                    <mac-interfaces-list>
                        <mac-interfaces>ge-0/0/4.0</mac-interfaces>
                    </mac-interfaces-list>
                </mac-table-entry>
            </ethernet-switching-table>
        </ethernet-switching-table-information>
        <cli>
            <banner>{master:0}[edit]</banner>
        </cli>
    </rpc-reply>

    {master:0}[edit]
    root@test#

    Attachment(s)

    txt
    ex4200.txt   5 KB 1 version


  • 19.  RE: Finding port IP address

    Posted 08-23-2010 10:37

    Dear All,

     

    Is my script corrupted or any steps missing?

     

    Thanks.

    Br,

    Sam



  • 20.  RE: Finding port IP address

    Posted 09-20-2010 08:48

    Hi!

     

    Same problem here (not sure, if I have to call the sript with the '0' or '0.0'  - so I tried both:

     

    root@ex2> op show-if-ips interface ge-0/0/0.0
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression.

    {master:0}
    root@ex2> op show-if-ips interface ge-0/0/0
    error: Invalid type
    error: runtime error: file /var/db/scripts/op/show-if-ips.slax element for-each
    error: Failed to evaluate the 'select' expression

     

    Interface is of type ethernet-switching:

    root@ex2> show configuration interfaces ge-0/0/0
    unit 0 {
        family ethernet-switching;
    }

     

    I downloaded the script twice in case a download had produced a corrupted file. Is this maybe duw to different junos-versions?

     

    Anyway -I tried a different approach to get the ethernet-switching table:

     

    template get-port($mac) {
            var $rpc = <get-ethernet-switching-table-information> {
            }
            var $switch-output = jcs:invoke($rpc);
              for-each($switch-output/ethernet-switching-table/mac-table-entry) {
                 if (contains(mac-address ,$mac)) {
                    <output> "IP "_ $ip _" has mac " _ $mac _" and is at port "_ mac-interfaces-list/mac-interfaces;
                 }
              }
    }


     

    template get-port($mac) {
            var $rpc = <get-ethernet-switching-table-information> {
            }
            var $switch-output = jcs:invoke($rpc);
              for-each($switch-output/ethernet-switching-table/mac-table-entry) {

                 if (contains(mac-address ,$mac)) {
                    <output> "IP "_ $ip _" has mac " _ $mac _" and is at port "_ mac-interfaces-list/mac-interfaces;
                 }
              }
    }

     

    My approach was a bit different though (tried to find out on what port a specific IP is reachable), but I guess, if you guys replace $mac with $interfcae, you should be able to loop thru the interfaces and retrive, what you're interested in.

     

    HTH,

      Kai

     

     



  • 21.  RE: Finding port IP address

    Posted 09-20-2010 08:51

    Oops - pasted the code fragment twice. Don't get confised - of course it's only needed once.

     

    Cheers,

    Kai