via: http://www.tecmint.com/ip-command-examples/
In this post, we are going to review how we can assign Static IP Address, Static Route, Default Gateway etc. Assigning IP Address on demand using IP command. IFCONFIG command is deprecated and replaced by IP command in Linux. However, IFCONFIG command is still works and available for most of the Linux distributions.
Note: Please take configuration file backup before doing any changes.
How do i Configure Static IP Address Internet Protocol (IPv4)
To configure static IP Address, you need to update or edit network configuration file to assign an Static IP Address to a system. You must be superuser with su (switch user) command from terminal or command prompt.
For RHEL/CentOS/Fedora
Open and edit network configuration file for (eth0 or eth1) using your favorite editor. For example, to assigning IP Address to eth0 interface as follows.
[root@tecmint ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Simple output:
DEVICE="eth0" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=192.168.50.2 NAME="System eth0" HWADDR=00:0C:29:28:FD:4C GATEWAY=192.168.50.1
For Ubuntu/Debian/Linux Mint
Assign Static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent changes as shown below.
auto eth0 iface eth0 inet static address 192.168.50.2 netmask 255.255.255.0 gateway 192.168.50.1
Next, restart network services after entering all the details using the following command.
# /etc/init.d/networking restart
$ sudo /etc/init.d/networking restart
1. How to Assign a IP Address to Specific Interface
The following command used to assign IP Address to a specific interface (eth1) on the fly.
# ip addr add 192.168.50.5 dev eth1
$ sudo ip addr add 192.168.50.5 dev eth1
Note: Unfortunately all these settings will be lost after a system restart.
2. How to Check an IP Address
To get the depth information of your network interfaces like IP Address, MAC Address information, use the following command as shown below.
# ip addr show
$ sudo ip addr show
Sample Output
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:28:fd:4c brd ff:ff:ff:ff:ff:ff inet 192.168.50.2/24 brd 192.168.50.255 scope global eth0 inet6 fe80::20c:29ff:fe28:fd4c/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:28:fd:56 brd ff:ff:ff:ff:ff:ff inet 192.168.50.5/24 scope global eth1 inet6 fe80::20c:29ff:fe28:fd56/64 scope link valid_lft forever preferred_lft forever
3. How to Remove an IP Address
The following command will remove an assigned IP address from the given interface (eth1).
# ip addr del 192.168.50.5/24 dev eth1
$ sudo ip addr del 192.168.50.5/24 dev eth1
4. How to Enable Network Interface
The “up” flag with interface name (eth1) enables a network interface. For example, the following command will activates the eth1 network interface.
# ip link set eth1 up
$ sudo ip link set eth1 up
5. How to Disable Network Interface
The “down” flag with interface name (eth1) disables a network interface. For example, the following command will De-activates the eth1 network interface.
# ip link set eth1 down
$ sudo ip link set eth1 down
6. How do I Check Route Table?
Type the following command to check the routing table information of system.
# ip route show
$ sudo ip route show
Sample Output
10.10.20.0/24 via 192.168.50.100 dev eth0 192.168.160.0/24 dev eth1 proto kernel scope link src 192.168.160.130 metric 1 192.168.50.0/24 dev eth0 proto kernel scope link src 192.168.50.2 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.50.1 dev eth0 proto static
7. How do I Add Static Route
Why you need to add Static routes or Manual routes, because that the traffic must not pass through the default gateway. We need to add Static routes to pass traffic from best way to reach the destination.
# ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
$ sudo ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
8. How to Remove Static Route
To remove assigned static route, simply type the following command.
# ip route del 10.10.20.0/24
$ sudo ip route del 10.10.20.0/24
9. How do I Add Persistence Static Routes
All the above route will be lost after a system restart. To add permanent Static route, edit file/etc/sysconfig/network-scripts/route-eth0 (We are storing static route for (eth0) and add the following lines and save and exist. By default route-eth0 file will not be there, need to be created.
For RHEL/CentOS/Fedora
# vi /etc/sysconfig/network-scripts/route-eth0 10.10.20.0/24 via 192.168.50.100 dev eth0
For Ubuntu/Debian/Linux Mint
Open the file /etc/network/interfaces and at the end add the persistence Static routes. IP Addresses may differ in your environment.
$ sudo vi /etc/network/interfaces
auto eth0 iface eth0 inet static address 192.168.50.2 netmask 255.255.255.0 gateway 192.168.50.100 #########{Static Route}########### up ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
Next, restart network services after entering all the details using the following command.
# /etc/init.d/network restart
$ sudo /etc/init.d/network restart
10. How do I Add Default Gateway
Default gateway can be specified globally or for in interface-specific config file. Advantage of default gateway is If we have more than one NIC is present in the system. You can add default gateway on the fly as shown below command.
# ip route add default via 192.168.50.100
$ sudo ip route add default via 192.168.50.100
Kindly correct me if i missed out. Please refer manual page doing man ip from terminal/command prompt to know more about IP Command.
相关推荐
PRENTICE_HALL-A_Practical_Guide_To_Linux_Commands_Editors_And_Shell_Programming
_Easy_to_manage_linux_commands_方便简单的管理linux命令__lflxp-cmd
Linux英文原版图书系列].PRENTICE_HALL-A_Practical_Guide_To_Linux_Commands_Editors_And_Shell_Programming.chm
书名为《Linux Commands and Shell Programming 2nd》,即第二版《Linux命令及Shell编程实用指南》,作者为Mark G. Sobell。这本书被描述为Linux命令行操作和Shell编程的必备读物,其内容通俗易懂,翔实可靠,专注于...
_Impressive_Linux_commands_cheat_sheet_CLI_writt_pls
### Quectel BC26 AT Commands Manual V1.0 关键知识点解析 #### 一、文档概述 **标题**:Quectel_BC26_AT_Commands_Manual_V1.0.pdf **描述**:该文档为NB-IoT模块系列中的BC26型号设备提供了AT命令手册,版本号...
linux_命令实践总结_commands-linux
Quectel_EC20_AT_Commands_Manual_V1.0.pdfQuectel_EC20_AT_Commands_Manual_V1.0.pdf
Quectel BC20 module features embedded TCP/IP stack, which enables the host to access the Internet directly over AT commands. This greatly reduces the dependence on PPP and TCP/IP protocol stacksand ...
2. 移动通信模块的TCP/IP相关AT指令集:文档中详细列出了如何使用AT指令与Quectel的EC2x、EG9x和EM05系列模块进行通信,特别是与它们的TCP/IP功能相关的操作。AT(Attention)指令集是用于与调制解调器和类似设备...
linux(ubuntu系统)常用命令汇总_linux_commands
Quectel_EC20_AT_Commands_Manual_V1.3 版本,相对以前版本有所更新!
首先,文档的标题明确指出这是关于“Quectel EC20 TCPIP AT Commands”的手册,即移远EC20模块的TCP/IP AT命令手册。AT命令是一种用于控制调制解调器和其他通信设备的指令集,常用于无线通信模块中,通过串行端口...
4. **数据传输命令**:涵盖TCP/IP和UDP协议的AT命令,如AT+CIPSEND用于发送数据,AT+CIPRECV用于接收数据,AT+CIPSTATUS用于查询连接状态,这些命令是实现物联网设备间数据通信的核心。 5. **网络参数设置**:包含...
文档标题为《Quectel_EC20_R2.1_AT_Commands_Manual_V1.0.pdf》,文档描述为移远EC20 AT指令手册。文档中强调了提供及时、全面服务的宗旨,并提供了总部联系方式,包括电话、邮箱及网址。手册中包含了一系列的联系...
《Quectel GNSS SDK Commands Manual V1.4》是针对Quectel公司LC86L GNSS模块的一份详细技术文档,旨在帮助开发者理解和利用Quectel GNSS软件开发工具包(SDK)进行定位应用的开发。这篇文档将深入探讨该SDK的主要...
### Quectel EC20 R2.0 AT Commands Manual V1.0 #### 简介 本手册为移远通信发布的《Quectel EC20 R2.0 AT Commands Manual V1.0》(以下简称“手册”),该文档详细介绍了EC20系列LTE模块的AT命令集及相关功能...
根据提供的文档信息,“FIBOCOM_L610_AT_Commands_User_Manual_V3.6.5.pdf”是一份关于广和通L610模块的AT指令手册,旨在为用户提供详细的AT命令使用指南。本手册包含了多个版本的迭代记录、版权说明以及具体的AT...
[Linux英文原版图书系列].PRENTICE_HALL-A_Practical_Guide_To_Linux_Commands_Editors_And_Shell_Program [Linux英文原版图书系列].PRENTICE_HALL-Building_Applications_With_The_Linux_Standard_Base [Linux英文...