Vxwroks常用的网络命令

最近了解了一下vxworks的几个常用的网络命令, 目的在于可以通过这些常用的命令可以单独调试vxworks网络协议栈相关的代码;
主要参考了一下vxworks的shell命令指导;

下面简单介绍了一下,

一. ifconfig

设置/查看网络接口配置信息
 

设置命令格式如下

ifconfig "interface [protocol] [parameter parameterValue]"

/*
也可以带上flags

ifconfig "[flags] [interface] [protocol]"
The following combinations of flags are valid when using ifconfig to generate
reports:
ifconfig "[-L] interface [ protocol ]"
ifconfig "-a [-L] [-d] [-u] [ protocol ]"
ifconfig "-l [-d] [-u] [ protocol ]"
ifconfig "[-L] [-d] [-u]" 

The flags values apply when the ifconfig command (or ifconfig( ) call) is used
to generate a report.
Use -a instead of specifying an interface value if you want a report containing
information on all interfaces.
Use -d to limit the report to down interfaces.
Use -l to limit the report to a simple list of all interfaces without additional
information.
Use -L to request lifetime information on an IPv6 address presented as a time
offset string.
Use -u to limit the report to up interfaces.
*/

在shell下输入ifconfig -h可以查看该命令的帮助信息

/*

NAME
   ifconfig - configure network interface parameters

SYNOPSIS
   ifconfig <interface> inet <address> [optional parameters]
   ifconfig <interface> <family> add <address> [optional parameters]
   ifconfig <interface> <family> delete <address>
   ifconfig <interface> <family> dstaddr <address>
   ifconfig <interface> mtu <value>
   ifconfig <interface> lladdr <string>
   ifconfig <interface> up
   ifconfig <interface> down
   ifconfig <interface> detach
   ifconfig <interface> promisc
   ifconfig <interface> -promisc
   ifconfig <interface> dhcp
   ifconfig <interface> -dhcp
   ifconfig <interface> vr <value>
   ifconfig [<interface> | -a]
   ifconfig <interface> [create | destroy]
   ifconfig <interface> vlan <tag> vlanpri <value> vlanif <iface>
   ifconfig <interface> <family> tunnel <local> <remote> [ttl]
   ifconfig <interface> link2

DESCRIPTION
   ifconfig is used to assign an address to a network interface and/or
   configure network interface parameters.

COMMANDS
   -a           List all interfaces.
   -v           Verbose output. NOTE: this switch must be the first
                switch of all if used.
   inet <a>     Change the primary IPv4 address.
   add <a>      Add 'a' IPv4 or IPv6 address.
   delete <a>   Delete 'a' IPv4 or IPv6 address.
   dstaddr <a>  Set remote address to 'a' (inet and PPP only).
   mtu <v>      Set interface MTU to 'v'.
   lladdr <a>   Set interface link address to 'a'.
   up           Bring the interface up.
   down         Bring the interface down.
   detach       Detaches interface (note: must be down first).
   vr <v>       Set virtual router to 'v' (default = 0).
   dhcp         Enable dhcp auto configuration (inet only).
   -dhcp        Disable dhcp auto configuration (inet only)
   link[0-2]    Enable special processing at the link level.
   -link[0-2]   Disable special processing at the link level.
   create       Create the specified network pseudo-device.
   destroy      Destroy the specified network pseudo-device.
   vlan <tag>   The virtual LAN tag (1-4095). Must be set at the
                same time as vlanif.
   vlanif <iface> The physical Ethernet interface to use for this
                virtual lan.
   vlanpri <value>   Set vlan class of service to 'value'. This optional
                     3-bit value is inserted to the vlan tag header
                     for packets sent from the vlan pseudo interface.
   tunnel <local> <remote> [ttl] If the interface is a gre or gif
                pseudo-interface, set the tunnel endpoints.
   link0        GRE tunnel: Enable minimal encapsulation (RFC 2002)
   -link0       GRE tunnel: Use normal GRE tunnel operation

VALUES
   <address>    The IPv4 or IPv6 address.
   <family>     Address family. 'inet' or 'inet6'.
   <interface>  Name of the interface.
   <value>      Numeric value depending on the command.

OPTIONAL PARAMETERS
   netmask <a.b.c.d>  Set interface netmask to 'a.b.c.d' (inet only)
   prefixlen <value>  Set interface prefix (mask length) length to 'n'
   temporary          The address is temporary (inet6 only)
   tentative          Perform DAD before setting address (inet6 only)
   anycast            The address is anycast (inet6 only)
   homeaddress        The address is a homeaddress (inet6 only)
   preferred <value>  Number of seconds this address is preferred (inet6 only)
   valid <value>      Number of seconds this address is valid (inet6 only)
*/

直接输入ifconfig会显示系统所以接口的配置情况;

如下:

 /*
lo0
        Link type:Local loopback  Queue:none
        inet 127.0.0.1  mask 255.255.255.255
        UP RUNNING LOOPBACK MULTICAST
        MTU:1500  metric:1  VR:0  ifindex:1
        RX packets:236944 mcast:0 errors:0 dropped:2
        TX packets:236944 mcast:0 errors:0
        collisions:0 unsupported proto:0
        RX bytes:14M  TX bytes:14M

vl1     Link type:Ethernet  HWaddr 00:d0:95:68:08:01  Queue:none
        inet 192.168.1.1  mask 255.255.255.0  broadcast 192.168.1.255
        UP RUNNING SIMPLEX BROADCAST MULTICAST
        MTU:1500  metric:0  VR:0  ifindex:2
        RX packets:533 mcast:289 errors:0 dropped:0
        TX packets:219 mcast:0 errors:0
        collisions:0 unsupported proto:0
        RX bytes:59k  TX bytes:15k

*/

对上面语法说明一下:


<interface> : 指lo0, vll;

<family> : 指inet, inet6

parameter:

add :

    address   “192.168.1.1/16”
    eg 添加一个接口的ip地址  ifconfig vl1 inet add 192.168.1.1/16

delete:
    address   “192.168.1.1/16”
    eg  删除一个接口ip地址  ifconfig vl1 inet delete  192.168.1.1/16


/*
anycast: ipv6的任播地址 
preferred: Set the preferred lifetime for the specified IPv6 address
prefixlen : 默认为64
tentative  :Set the tentative bit in the specified IPv6 address.
-tentative : Clear the tentative bit in the specified IPv6 address
valid :   Set the valid lifetime for the specified IPv6 address.   
*/
 
up:    ifconfig vl1 up     修改的是接口下flag标志位: UP  RUNNING  SIMPLEX  BROADCAST  MULTICAST
 
down:  ifconfig vl1 down   接口的flag属性变化:SIMPLEX BROADCAST MULTICAST 
 

mtu:  设置网络接口最大的mtu值  
 
lladdr : 设置网络接口链路地址  
       eg: ifconfig vl1 lladdr 00:00:00:00:01:01

 
二: route

route命令配置的语法格式如下:

route [-V routetab] [-n] command [[modifiers] args]

直接输入route,会显示route命令的帮助信息:

/*
 route NAME
     route - manually manipulate the routing tables

SYNOPSIS     route [-V routetab] [-n] command [[modifiers] args]

DESCRIPTION
     route is a utility used to manually manipulate the network routing
     tables.
     The route utility supports a limited number of general options, but a
     rich command language enables the user to specify any arbitrary request
     that could be delivered via the programmatic interface.

     The route utility provides several commands:
     add         Add a route.
     delete      Delete a route.
     change      Change aspects of a route (such as its gateway).
     get         Lookup and display the route for a destination.
     show        Print out the route table (similar to netstat -r)
     monitor     Continuously report any changes to the routing information
                 base, routing lookup misses, or suspected network
                 partitionings.
     vr          Add/delete a virtual route table

     The monitor command has the syntax:

           route [-n] monitor
     The vr command has the syntax:

           route vr [[-T <table>] -add | -delete | -addbyname] <vr_index>
        vr_index 0 (the default route table) cannot be added or deleted.
        The new route table will be completely empty.
     The following options are supported:
     -T <table>          Create a new FIB within the VR.
     -add                Add a new VR
     -delete             Delete a VR
     -addbyname          Add a new VR, <vr_index> is the name of the VR

     The route utility commands have the following syntax:

           route [-n] <command> [-net | -host] [-<option...>] <dest_ip> [<gate_ip>]

      where net or host forces the destination to be interpreted as a network or
      a host, respectively)
     <dest_ip> is the IPv4/IPv6 destination host or network address
     <gate_ip> is  the IPv4/IPv6 host serving as the gateway.

     The following additional options are supported:
     -V <vr>             Specifies virtual router index. 0 if not specified.
                         Must be the first switch if present.
     -n                  Disables DNS address lookup.
     -nollinfo           Do not show routes which have the IPNET_RTM_LLINFO flag set.
     -T <table>          Specifies route table ID. 254 if not specified.
     -inet               IPv4 route (default)
     -inet6              IPv6 route
     -netmask <a.b.c.d>  Specify IPv4 destination netmask for -net routes.
                         The netmask is stated in dotted decimal notation
                         (<a.b.c.d>), where each portion of the mask is
                         an integer between 0-255, representing the value
                         of the bytes in that position in the mask.
     -prefixlen <val>    Prefix length for -net routes.
     -dev <ifname>       Device name. This option must be used if <gate_ip> is not
                         specified. It may also be used if <gate_ip> is specified
                         and <gate_ip> can be reached by more than one link;
                         in such a case, use -dev <ifname> to specify which
                         link should be used.
     If the destination is directly reachable via an interface requiring no
     intermediary system to act as a gateway, specify the '-iface' route flag;
     the gateway given is the address of this host on the common network,
     indicating the interface to be used for transmission.  For further information
     on '-iface', see the description of route flags, below.  The optional '-netmask'
     qualifier is used to manually add subnet routes with netmasks different
     from that of the implied network interface. Specify an additional address
     parameter (to be interpreted as a network mask).  You can override the implicit
     network mask generated in the IP_AF_INET case by using this option
     after the destination parameter.  You can also use the modifier '-prefixlen'
     for similar purposes in the IPv6 case.

     Routes have associated flags, which influence operation of the protocols
     when sending to destinations matched by the routes.  To set (or sometimes
     clear these flags, indicate the following corresponding
     modifiers:

     -blackhole IPNET_RTF_BLACKHOLE  - silently discard pkts (during updates)
     -cloning   IPNET_RTF_CLONING    - generates a new route on use
     -host      IPNET_RTF_HOST       - route for a single node
     -iface    ~IPNET_RTF_GATEWAY    - destination is directly reachable
     -llinfo    IPNET_RTF_LLINFO     - validly translates proto addr to link addr
     -mbinding  IPNET_RTF_MBINDING   - packet sent along this route must be sent to
                                       multiple egress interfaces and/or multiple gateways
     -net      ~IPNET_RTF_HOST       - route for a (sub)network
     -nostatic ~IPNET_RTF_STATIC     - pretend route added by kernel or daemon
     -notdone  ~IPNET_RTF_DONE       - unresolved ARP/NDP entry
     -pref      IPNET_RTF_PREF       - always prefer this route
     -proto1    IPNET_RTF_PROTO1     - set protocol specific routing flag #1
     -proto2    IPNET_RTF_PROTO2     - set protocol specific routing flag #2
     -reject    IPNET_RTF_REJECT     - emit an ICMP unreachable when matched
     -skip      IPNET_RTF_SKIP       - stop searching this FIB and move to next one
     -static    IPNET_RTF_STATIC     - manually added route
     -tunnelend IPNET_RTF_TUNNELEND  - gateway specifies tunnel endpoint
     -xresolve  IPNET_RTF_XRESOLVE   - emit a message on use (for external lookup)

     The optional modifiers '-rtt', '-rttvar', '-mtu', '-hopcount', and '-expire'
     provide initial values to quantities maintained in the routing entry by
     transport level protocols, such as TCP.  In a change or add command where
     the destination and gateway are not sufficient to specify the route (as in
     the ISO case, where several interfaces may have the same address), the router
     can use the '-ifp' or '-ifa' modifiers to determine the interface or interface
     address.

EXAMPLES
     (1) Add default IPv4 gateway to 10.1.1.1:
         > route add default 10.1.1.1
     (2) Add IPv4 network route 14.1/16 on specified interface:
         > route add -dev eth0 -net -netmask 255.255.0.0 14.1.0.0
     (3) Add IPv4 route for host 15.1.6.7 to gateway 10.1.1.22:
         > route add -host 15.1.6.7 10.1.1.22
     (4) Add default IPv6 gateway to FEC0::1:0:0:0:6:
         > route add -inet6 default FEC0::1:0:0:0:6
     (4) Add a new virtual router
         > route vr -add 1

*/

对该route语法格式说明:

route [-V routetab] [-n] command [[modifiers] args]

-V: 指定vr_index  默认为0;常常路由器可以虚拟出多个路由器;vr_index唯一标示一台路由器;
-n: 关闭dns地址查找

根据实际使用情况会将上面语法格式拆分如下几种格式:

  route <command> [-net | -host] [-<option...>] <dest_ip> [<gate_ip>]

  route <command>

  route <command> [[-T table] -add | -delete | -addbyname] vr_index

<command>: add 或delete,change,show等;

添加路由  route add [-net | -host] [-<option...>] <dest_ip> [<gate_ip>]
  eg:
 route -V 0 add -net 192.168.11.0/24 192.168.10.80
    add net 192.168.11.0: netmask 255.255.255.0: gateway 192.168.10.80


删除路由  route delete [-net | -host] [-<option...>] <dest_ip> [<gate_ip>]

  eg:
   route -V 0 delete -net 192.168.11.0/24 192.168.10.80
    delete net 192.168.11.0
改变路由  route change

显示路由  route show

添加/删除虚拟路由表:  route vr [[-T table] -add | -delete | -addbyname] vr_index
-T table : table为当前的vr
 
 eg 当前vr为0:
 route vr -T 0 -add  1 或者 route vr -add 1
 route vr -T 0 -delete  1


监控变化路由 route monitor

三 arp:

/*
Name
    arp – dynamically display and configure ARP and proxy ARP information, or for test purposes


Synopsis
   arp [-silent] [-V routetab] [-i ifname] -a
   arp [-silent] [-V routetab] [-i ifname] -A
   arp [-silent] [-V routetab] -d hostaddress
   arp [-silent] [-V routetab] [-i ifname] [-p] [-t] -s hostaddress ether_addr
   arp [-silent] [-V routetab] [-i ifname] -r hostaddress
Description
   The ARP program displays and modifies the Internet-to-Ethernet address
translation tables used by the ARP. With no flags, the program displays the current
ARP entry for hostname. The host may be specified by name or by number, using
Internet dot notation.


The arp options are:

   -silent
        Suppress output. MUST be the first argument.

   -i ifname
        Specify interface. If not specified, the first interface that uses ARP is used.

   -t
        Temporary ARP entry. The entry times out normally.

   -p
        Public ARP entry (proxy ARP entry). A proxy ARP entry is shown as a route
        with the proto2 flag set (shown as ‘2’ with route/netstat).

   -r
        Send an ARP request to the host address.

   -V routetab
          Specify route table. 0 if not specified.


The arp commands are:
    -a
       The program displays all of the current ARP entries.
    -A
       Erase all ARP entries on the interface.
    -d
         Delete an entry for the host called hostaddress.
   
    -s hostaddress ether_addr
        Create an ARP entry for the host having the specified IPv4 and Ethernet
        address. The Ethernet address is given in the standard format of six hex bytes
        separated by colons (for example, 01:02:03:04:05:06). The entry is permanent
        unless the -t flag is used, but can be removed by using the arp -d command.
        Public (proxy ARP) entries are added using the -p flag.
*/

添加一条arp:
arp -s  192.168.1.1  00:00:00:00:00:01   arp -d 删除不掉的
 
arp  -t  -s  192.168.1.1  00:00:00:00:00:01   arp -d 可以删除


四:netstat : 查看网络状态, 除了能观察本机的启动接口外,还能观察 socket的传输接口数据。

/*
NAME
     netstat - show network status

SYNOPSIS
     netstat -h
     netstat [-an] [-f address_family] [-V vr] [-p protocol]
     netstat -r [-nl] [-f address_family] [-V vr]
     netstat -s [raw|ip|icmp|sctp|udp|tcp|ip6|icmp6]

DESCRIPTION
     The netstat command symbolically displays the contents of various
     network-related data structures.

     -a    Show the state of all sockets; normally sockets used by server
           processes are not shown.
     -f <address_family>
           Limit statistics or address control block reports to those of the
           specified address family.  The following address families are
           recognized: inet, for IP_AF_INET; inet6, for IP_AF_INET6.
     -h    Help, this usage menu
     -l    Do not show routes where the LLINFO flag is set.
     -n    Show network addresses as numbers. Default is to lookup symbolic
           names for the addresses.
     -p <protocol>
           Show statistics about protocol, which is either a well-known name
           for a protocol or an alias for it.
     -r    Show the routing tables
     -P    Show which process that owns the socket.
     -T <table> Specify route table ID. 254 if not specified.
     -V <vr> Specify virtual router index. 0 if not specified.
     -s    Display networking statistics.

*/


五: ping :   发送ICMPv4 ECHO_REQUEST报文到网络主机,常用于检查网络是否可达;

/*
Name
      ping - send ICMPv4 ECHO_REQUEST packets to network hosts
Synopsis
      ping [-silent] [-ADbnrx] [-I ifname] [-S src_addr] [-T tsonly| tsandaddr | tsprespec]
            [-Q tos] [-x] [-V vr] [-c count] [-s packetsize] [-t ttl] [-w ms] host
Description
      ping uses the ICMPv4 protocol’s mandatory ECHO_REQUEST datagram to elicit
      an ECHO_REPLY from a host or gateway.

The ping options are:
     -A  Add router alert option to each sent ping request.
     -b  Allow pinging a broadcast address.
     -c  count Stop after sending count ECHO_RESPONSE packets.
     -D  Set the DF (don’t fragment) flag on each sent ping request.
     -I ifname  Specify outgoing interface.
     -n  Numeric output only. No attempts are made to look up names for host addresses.

     -Q tos  Specify the Type of Service field in the IPv4 header.
     -r      Bypass the normal routing tables and send directly to a host on
             an attached network.
     -R      Record route. Includes the RECORD_ROUTE option in the ECHO_REQUEST
             packet. IPNET will discard ECHO_REQUEST that contains RECORD_ROUTE
             Note2: the record route IP option cannot hold more than 9 hops.
             Many nodes ignore or discard this option.
     -s packetsize
             Specifies the number of data bytes to be sent. The default is
             56, which translates into 64 ICMP data bytes when combined with
             the 8 bytes of ICMP header data.
     -S src_addr  Specifies the address to use a source address when sending.
     -t ttl  Use the specified time-to-live.
     -T timestamp options
             Include IP timestamp option. timestamp can be tsonly (only timestamp)
             tsandaddr (address and timestamp) or
             tsprespec host1 [host2 [host3 [host4]]] (timestamp specific hops)
     -x      Send a ICMP timestamp request instead of a ECHO request.
     -V vr   Specify virtual router. 0 if not specified.
     -w timeout in milliseconds, default is 1000 ms.
     -silent no output, returns success or failure.

*/

 

值得注意的是:

vxworks的shell命令提供了2种模式配置;

1). 命令行翻译模式 command interpreter mode
2). C翻译模式 C interpreter mode  : 所有参数需要使用 “”

posted on 2012-12-29 20:16  幸运布衣  阅读(5480)  评论(0编辑  收藏  举报