Linux |
||
Network
In this page, I will show you the ways to get the configuration information on NIC (Network Interface Card) and configure it as you like. This is based on my try on Ubuntu.
View the current NIC configuration - the command ifconfig
Example : # ifconfig
Example : # ifconfig eth0 eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'
View the current NIC configuration - the command ip
Example : # ip addr
Example : # ip addr show
Example : # ip addr show eth0 eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ip''
Assign an IP address for a network interface card (NIC)
Example : # ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 up eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig' 192.168.1.2 : IP address to be assigned for the NIC netmask 255.255.255.0 : set subnet mask to be 255.255.255.0 up : This is not mandatory, but I recommend this to make it sure that NIC is enabled after this command
Enable an IP address for a network interface card (NIC)
Example : # ifconfig eth0 up eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'
Disable an IP address for a network interface card (NIC)
Example : # ifconfig eth0 down eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig'
Adding IP address (Temporay) to a Network Interface Card (NIC)
Example : # sudo ip addr add 192.168.1.100/24 dev eth0
Example : # sudo ip addr add 192.168.1.100/24 dev eth0 label eth0:1 eth0 : Network Interface Card Name (you can figure out this name for your PC by 'IP' command NOTE : You can check the result of this command using 'ip addr'. NOTE : The IP added by this method will be disappear if you reboot the pc.
Deleting IP address (Temporay) from a Network Interface Card (NIC)
Example : # sudo ip addr del 192.168.1.100 dev eth0 eth0 : Network Interface Card Name (you can figure out this name for your PC by 'IP' command
Adding a IP address (Permanent) to a Network Interface Card (NIC)
This is a little bit complicated. A single command would not do this. You need to change the contents of a interface configuration file as shown in the following example.
Open up the file named 'interfaces' located in '/etc/network' (i.e, open up the file /etc/network/interfaces) using text editor and add following lines and reboot the PC auto eth0:1 iface eth0:1 inet static address 192.168.1.100 gateway 192.168.1.254 netmask 255.255.255.0 eth0:1 => this is an alias for the NIC (a kind of virtual NIC) to which this IP will be assigned.
Adding the default Gateway to a network interface card(NIC)
Example : # route add default gw 192.168.0.1 wlan0
After this, you can confirm the default gateway options using 'ip route' command as below.
# ip route default via 192.168.0.1 dev wlan0 default via 192.168.1.254 dev eth0 onlink linkdown 192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.28 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 linkdown
Example : # ifconfig eth0 mtu 1500 eth0 : Network Interface Card Name (you can figure out this name for your PC by 'ifconfig' mtu 1500 : set mtu to be 1500
Example (Enable the promiscuous mode) : # ifconfig eth0 promisc
Example (Disable the promiscuous mode) : # ifconfig eth0 -promisc
Allowing Wireshark to capture packets
Sometimes you would see the error message on Wireshark saying "You didn't specify on which to capture packets". Then you may open "Capture" dialog and try to select "Interface",but don't see any interface name in it. In this case, you may try following.
Example : # setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap
Deleting (Removing) a Network Interface
You can delete an existing network interface using 'ip link delete'. For example, if you want to delete a network interface named 'eth10', you can do it as follows.
Example : # ip link delete dev eth10
Adding a Virtual Network Interface tied to an existing physical NIC
This cannot be done in single steps. You need to go through several steps to do this. For example, let's assume that you want to create a virtual interface named 'veth' which is using the same physical interface named 'peth'. Also let's assume that peth is connected to a network (a router or modem) which support dhcp. This can be done in a few steps in sequence as below. (NOTE : If you are already familiar with basic operation of Linux Network interface, just following example would be enough, but if not, you may want a more detailed tutorial like this)
Example : # ip link add link peth name veth address aa:bb:cc:dd:ee:ff type macvlan # ifconfig veth up # dhclient –v veth NOTE : 'aa:bb:cc:dd:ee:ff' is the MAC address for the virtual network (veth in this example). I would suggest you to assign a MAC address that is not likely to be used anywhere else in your network. You may easily get this type of MAC address here.
Deleting the whole NAT table (IPv4)
It doesn't seem that we have any single command that can do this job. You would need to go through a multiple steps in sequence. Following is an example. Run all of the commands one by one.
Example : # iptables -P INPUT ACCEPT # iptables -P FORWARD ACCEPT # iptables -P OUTPUT ACCEPT # iptables -t nat -F # iptables -t mangle -F # iptables -F # iptables -X
Deleting the whole NAT table (IPv6)
It doesn't seem that we have any single command that can do this job. You would need to go through a multiple steps in sequence. Following is an example. Run all of the commands one by one.
Example : # ip6tables -P INPUT ACCEPT # ip6tables -P FORWARD ACCEPT # ip6tables -P OUTPUT ACCEPT # ip6tables -t nat -F # ip6tables -t mangle -F # ip6tables -F # ip6tables -X
|
||