Network Configuration on Linux

The Linux operation system is mainly used in kinds of servers, in Internet, that allow the general users to access web pages and the administrators to administrate them in remote, for which network configuration is particularly important. Before exploring how to configure network on Linux, a great amount of fundamental knowledge of Computer Networks is required and will be introduced first in this essay. I highly recommend you the book, Computer Networking: A Top-Down Approach, which explores the computer networks far more detail and is also easy to understand. 

1. Fundamental knowledge of Computer Network

For those who have already studied Computer Networks, there are several links, helping you to review, which are optional.

a. Network Topology

The bus topology, ring topology and star topology are three most common topologies applied in computer networks.

https://en.wikipedia.org/wiki/Network_topology

Carrier Sense Multiple Access with Collision Detection (CSMA/CD) is a media access control method used in the bus network, which ensures each host connected to the bus network to transmission correctly. Thus, a link for CSMA/CD is provided bellow.

https://en.wikipedia.org/wiki/Carrier_sense_multiple_access_with_collision_detection

b. Hub, Bridge, Switch and Router

Those are key physical devices, needed in Network infrastructures, in which multiple protocols defined in several layers of OSI model are supported.

http://www.cisco1900router.com/tutorial-of-differences-between-hub-bridge-switch-and-router.html

https://en.wikipedia.org/wiki/OSI_model

c. MAC addr, IP addr, Port & Socket

The MAC addr, also called physical addr, is a unique identifier assigned to network interfaces which are physical devices implementing computers' networking function. The MAC addr is used in local network for transmission among hosts. However, it's not a serviceable solution for transmission among several local networks or in a large network. Because it would cause broadcast storm which could make the entire network unavailable at all. Therefore, The IP addr, also called logical addr, is created to solve this problem. Each IP addr is divided into two parts, network addr and host addr, by and operation with netmask. Port is actually the address of processes running on a operation system. Socket is the combination of an IP addr and a port number.

https://en.wikipedia.org/wiki/MAC_address

https://en.wikipedia.org/wiki/IP_address

http://www.computerhope.com/jargon/n/netmask.htm

https://en.wikipedia.org/wiki/Port_(computer_networking)

https://en.wikipedia.org/wiki/Network_socket

d. Routing

Routing is the process of selecting the best paths which take the lest time for hosts to transmit between two hosts in a network, which could base on the shortest distance strategy or the idlest path strategy. It's the essential part of the Computer Network and hard to explain in a short time. A comprehensive and detailed textbook, like Computer Networking: A Top-Down Approach, can be helpful.

https://en.wikipedia.org/wiki/Routing

e. TCP & UDP

TCP and UDP are two protocols that defined in the transport layer of OSI model. TCP provides a reliable but slower connection between two hosts, in which the three-way-handshake is involved.  However, UDP provides a unreliable but faster connection between two hosts.

https://en.wikibooks.org/wiki/Communication_Networks/TCP_and_UDP_Protocols

http://www.tcpipguide.com/free/t_TCPConnectionEstablishmentProcessTheThreeWayHandsh-3.htm

2. Network Configuration on Linux

What a normal host accessing to the Internet requires to configure ahead are generally IP, Netmask, Gateway, Hostname, DNS and Routing information, which can be statically assigned by administrator or automatically configured by DHCP (Dynamic Host Configuration Protocol). It's important for us to keep in mind that the network function of Linux is defined in it's kernel. Thus, the IP addr don't belong to the network interface but is owned by the kernel.

/*All configuration implemented by command is real time but temporary. Wanting a persistent change, you should edit the configuration files.*/

a. ifconfig

Print all information of all network interfaces or a specific one in your host.

# ifconfig -a

# ifconfig INTERFACE_NAME

Change the IP addr and Masknet of the network interface whose alias is eth0.

# ifconfig INTERFACE_NAME IP/MASK

Turn on or turn off the network interface whose alias is eth0.

# ifconfig INTERFACE_NAME [up|down]

b. Start, Stop, Restart the network or Check its status

# /etc/init.d/network [start|stop|restart|status]

c. route

Print all record-routes.

# route

Add a record-route which suggests that a packet heading for a specific net/host should be transmit to next hop.

# route add -net|-host DEST gw NEXTHOP

Delete a specific record-route.

# route del -net|-host DEST

Show numerical address instead of it's symbolic hostname.

# route -n

d. Network configuration file & Its interfaces configuration files

# cat /etc/sysconfig/network

# cat /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME

e. Routing configuration file

# cat /etc/sysconfig/network-scripts/route-INTERFACE_NAME

f. DNS configuration file

Configure DNS server.

# cat /etc/resolv.conf

Configure domain name resolution in local.

# cat /etc/hosts

format: IP    hostname    alias

g. ip

Display devices' attributes of all network interfaces or a specific one in your host.

# ip [-s] link show [INTERFACE_NAME]

Turn on or turn off the network interface whose alias is eth0.

# ip link set INTERFACE_NAME [up|down]

Add a new IP addr to a specific network interface and give it an alias.

# ip addr add IP_ADDRESS dev DEV [label ALIAS]

Delete a IP addr from a specific network interface.

# ip addr del IP_ADDRESS dev DEV

Display IP addrs, of all network interfaces or a specific one in your host, which begin with prefix PREFIX.

# ip addr show dev INTERFACE_NAME to PREFIX

Delete IP addrs, of all network interfaces or a specific one in your host, which begin with prefix PREFIX.

# ip flush dev DEV to PREFIX


Reference:

[1] Linux.die.net, (2015).ifconfig(8): configure network interface - Linux man page. [online] Available at: http://linux.die.net/man/8/ifconfig [Accessed 16 Oct. 2015].

[2] Linux.die.net, (2015).ip(8) - Linux man page. [online] Available at: http://linux.die.net/man/8/ip [Accessed 16 Oct. 2015].

[3] Linux.die.net, (2015).route(8): show/change IP routing table - Linux man page. [online] Available at: http://linux.die.net/man/8/route [Accessed 16 Oct. 2015].

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 161,192评论 4 369
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,186评论 1 303
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,844评论 0 252
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,471评论 0 217
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,876评论 3 294
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,891评论 1 224
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,068评论 2 317
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,791评论 0 205
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,539评论 1 249
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,772评论 2 253
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,250评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,577评论 3 260
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,244评论 3 241
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,146评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,949评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,995评论 2 285
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,812评论 2 276

推荐阅读更多精彩内容