码迷,mamicode.com
首页 > 系统相关 > 详细

linux网络属性配置

时间:2016-03-23 06:48:49      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:网络属性配置

linux网络属性配置分动态分配和静态指定

动态分配主要依靠DHCP服务器

静态指定需要命令手动分配


静态指定命令三家族

ifcfg家族

iproute2家族

nm家族


ifcfg家族:

ifconfig:接口及地址查看和管理

ifconfig -a 显示所有接口包括inactive

ifconfig interface up|down 开关端口

技术分享

ifconfig interface address netmask 修改端口ip地址

技术分享

route:路由查看及管理

route -n 查看主机路由条目以数字形式表示

技术分享

route add [-net|-host] target [netmask Nm] [gw Gw] [[[dev] If] 添加路由

route del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If] 删除路由

技术分享

添加删除默认路由

route add default gw 192.168.10.1 

route del default


netstat:状态及统计数据查看


netstat -rn 与 route -n 相同:显示路由

netstat [--tcp|-t] [--udp|-u] [--udplite|-U] [--sctp|-S] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e[--extend|-e]] [--program|-p]

常用组合:

-tan:数字形式显示所有TCPsockets

-uan:数字形式显示所有UDPsockets

-tnl:数字形式显示监听状态TCPsockets

-unl:数字形式显示监听状态UDPsockets

-tunlp:数字形式显示监听状态TCP、UDPsockets的相关进程及PID

技术分享

netstat -i 显示所有接口统计数据

netstat -Iinterface 显示指定接口统计数据

技术分享


iproute2家族:

ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT := { link | addr | route | netns }

ip link:网络设备配置

ip link set DEVICE { up | down }|multicast { on | off } |name NEWNAME |mtu MTU |netns PID

ip link show DEVICE

技术分享

ip route:路由表管理

ip route { add | del | show | flush | get }

示例:

# ip route add 192.168.1.0/24 via 10.0.0.1 dev eth1 src 10.0.20.100

# ip route add default via GW

# ip route delete 192.168.2.0/24

技术分享

# ip route get 192.168.3.0/24


ip address:协议地址管理

ip address { add | del } IFADDR dev STRING

ip address { show | flush } [ dev STRING ]

技术分享


ip netns:进行网络命名空间管理

ip netns list - show all of the named network namespaces

ip netns add NAME - create a new named network namespace

ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)

ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network namespace


ss:状态及统计数据查看

ss [options] [ FILTER ]

options

-t, --tcp Display TCP sockets.

-u, --udp Display UDP sockets.

-w, --raw Display RAW sockets.

-l, --listening Display only listening sockets (these are omitted by default).

-a, --all Display both listening and non-listening (for TCP this means established        connections) sockets.

-n, --numeric Do not try to resolve service names.

-e, --extended Show detailed socket information

-m, --memory Show socket memory usage.

-p, --processes Show process using socket.

-o, --options Show timer information.

FILTER := [ state STATE-FILTER ] [ EXPRESSION ]

示例

ss -o state established ‘( dport = :ssh or sport = :ssh )‘

Display all established ssh connections.


nm(Network Manager)家族(CentOS 7)

nmcli:命令行工具

nmcli  [ OPTIONS ] OBJECT { COMMAND | help }

 OBJECT := { general | networking | radio | connection | device | agent  }

   general - general NetworkManager status and operations

     COMMAND := { status | hostname | permissions | logging }

   networking - get or set general networking state of NetworkManager

     COMMAND := { [ on | off | connectivity ] }

   radio - get or set radio switch states

    COMMAND := { all | wifi | wwan | wimax }

   connection - start, stop, and manage network connections

    COMMAND := { show | up | down | add | edit | modify | delete | reload | load }

   device - show and manage network interfaces

    COMMAND := { status | show | connect | disconnect | delete | wifi | wimax }

修改属性

modify [--temporary] [ id | uuid | path ] <ID> [+|-]<setting>.<property> <value>

技术分享

nmtui:text window 工具

Text User Interface for controlling NetworkManager


配置文件

IP/NETMASK/GW/DNS等属性的配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE

其可通过vim等文本编辑器直接修改

技术分享

也可以使用专用的命令的进行修改

CentOS 6:system-config-network (setup),

CentOS 7: nmtui


路由的相关配置文件:/etc/sysconfig/networkj-scripts/route-IFACE

支持两种配置方式,但不可混用;

(1) 每行一个路由条目:

TARGET  via  GW

(2) 每三行一个路由条目:

ADDRESS#=TARGET

NETMASK#=MASK

GATEWAY#=NEXTHOP

注:用虚拟机启用第二块儿网卡路由没有添加成功。。。。

本文出自 “liberalism” 博客,请务必保留此出处http://edonkey.blog.51cto.com/887243/1754034

linux网络属性配置

标签:网络属性配置

原文地址:http://edonkey.blog.51cto.com/887243/1754034

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!