Showing posts with label Networks. Show all posts
Showing posts with label Networks. Show all posts

Tuesday, July 22, 2014

Start network after boot on CentOS

You have two options, use the network-scripts or networkmanager

For myself, I want to use the network scripts. 
chkconfig NetworkManager off
chkconfig network on
Disable the NetworkManager and enable the old network

Then, you need to make sure you are setting up a correct network script at /etc/sysconfig/network-scripts/ifcfg-eth0

make sure ONBOOT=yes

Example of external network interface using DHCP:

$ vim /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1
HWADDR=00:26:B9:3E:33:A9
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
DHCP_HOSTNAME=sr2s1
PEERDNS=yes

Example of internal network interface using static IP:

vim /etc/sysconfig/network-scripts/ifcfg-p1p1
DEVICE=p1p1
HWADDR=00:1B:21:44:8D:70
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.21
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
NAME=p1p1


Thursday, February 13, 2014

unlock a deny host

1.
$ service denyhosts stop

2.
$ vim /etc/hosts.deny
delete the IP from the file

3.
$ cd /va/lib/denyhosts
$ grep -iRH IP ./*

[root@server denyhosts]# grep -iRH IP ./*
./hosts:IP:0:Sun Feb  9 11:27:57 2014
./hosts-restricted:IP:0:Sun Feb  9 11:27:57 2014
./hosts-root:IP:0:Sun Feb  9 11:27:57 2014
./hosts-valid:IP:11:Sun Feb  9 11:31:57 2014

./users-hosts:username - IP:11:Sun Feb  9 11:31:57 2014

delete the IPs from all of the files. 

4. 
$ service denyhosts start

Friday, January 24, 2014

Network Configuration on Ubuntu

Sample configuration file:

@sr2s17:~$ cat /etc/network/interfaces 
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

auto eth2
iface eth2 inet static
address 192.168.0.37

netmask 255.255.255.0


I use interface eth0 as the external network and eth2 as the internal network. 

After you install Ubuntu, the interfaces may not be up. Although you can use ethtool to detect if the interfaces are physically connected by cables, This approach is not accurate on Ubuntu (works on CentOS). 

For example, I know there are six interfaces on my server
eth0 and eth1 are on a broadcom network card, and eth2, 3, 4, 5 are on a Intel network card. 
I plugged the Ethernet cable to the eth2 interface, so I just need to write the script into /etc/network/interfaces, which help me to enable the eth2. Next, I run a $ /etc/init.d/networking restart

Monday, January 13, 2014

Configure the hostname in CentOS

Test a hostname if working:
nfslookup HOSTNAME
or
nfslookup IP_ADDRESS

to see if there is an entry in the DNS server

First, you need to have a correct network script in /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 


DEVICE=eth4                                   //device name
HWADDR=00:26:B9:38:4C:23            // mac address 
TYPE=Ethernet                         
ONBOOT=yes                                  // automatically connected after bootup
NM_CONTROLLED=no                     // does not use Network Manager, use ifcfg-eth4 script
BOOTPROTO=dhcp                         // use DHCP
DHCP_HOSTNAME=sr2s18              // configure DHCP hostname

PEERDNS=yes                                //Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default


Then, configure the hostname:

http://www.rackspace.com/knowledge_center/article/centos-hostname-change

1. set /etc/sysconfig/network

[root@sr2s16 ~]# cat /etc/sysconfig/network
NETWORKING_IPV6=no
HOSTNAME=sr2s16.example.com

NETWORKING=yes

2. configre /etc/hosts

[root@sr2s16 ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
129.174.114.142 sr2s16.example.com sr2s16
::1 sr2s16.example.com sr2s16

192.168.0.36 sr2s16.example.com sr2s16


3. restart network

$ service network restart









Friday, January 10, 2014

network configuration sample on Cent OS

External network interface using dhcp: /etc/sysconfig/network-script/ifcfg-eth4

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 

DEVICE=eth4
HWADDR=00:26:B9:38:4C:23
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

Internal network interface using static IP: /etc/sysconfig/network-script/ifcfg-eth0

[root@sr2s18 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:1B:21:44:96:10
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.38
BROADCAST=192.158.0.25
NETMASK=255.255.255.0
NAME=eth0

Run dhcp when system starts up on Cent OS

configure /etc/sysconfig/network-script/ifcfg-eth4

DEVICE=eth4
HWADDR=00:26:B9:38:4C:23
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

if you set the onboot=yes, the system will run dhcp when system boots

Fix nobody issue on CentOS/Ubunut using LDAP and NFS

CentOS

vim /etc/idmapd.conf
add Domain=example.com
restart the services
/etc/init.d/rpcidmapd restart and /etc/init.d/nfs restart

http://lfhck.com/question/100876/centos-6--ldap--nfs-file-ownership-is-stuck-on-nobody

Solved!
I happened to notice this line in /var/log/messages on my NFS server when I was attempting to mount an export from the remote client:
Feb 28 15:54:02 storage1 rpc.idmapd[1651]: nss_getpwnam: name 'nobody' does not map into domain 'localdomain'
This caused me to look at the first few lines of /etc/idmapd.conf:
[General]
#Verbosity = 0
# The following should be set to the local NFSv4 domain name
# The default is the host's DNS domain name.
#Domain = local.domain.edu
I then added Domain=subdomain.mycompany.com under the commented out "Domain" line. Saved, exited and then ran/etc/init.d/rpcidmapd restart and /etc/init.d/nfs restart.



Ubuntu

vim /etc/idmapd.conf
add Domain=example.com
reboot

Monday, December 30, 2013

IP Tables

$ iptables -L [--list]
list all of the IP table rules

$ iptables -F [--flush]
flush all of the IP table rules

$ service iptables save
save current iptables to /etc/sysconfig/iptables


Good article from linuxwave blog

http://linuxwave.blogspot.com/2013/11/manually-manipulating-iptables-in.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Linuxwave+%28linuxwave%29


Manually manipulating iptables in CentOS and Redhat

The iptables rules in redhat based distro is being kept by default in /etc/sysconfig/iptables and /etc/sysconfig/ip6tables. To manipulate the firewall, just add or remove rules from this file, and restart iptables services. For example, we want to allow tftp port, which is port 69 udp:
  1. Edit /etc/sysconfig/iptables
    • # vi /etc/sysconfig/iptables
  2. Add the following lines, before the final LOG and DROP lines for INPUT chain:
    • -A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
  3. Save and close the file
  4. Restart iptables service:
    • # /etc/init.d/iptables restart
  5. Check your new iptables rules, where -L is to list all rules in the selected chain, and -n is for printing port in numeric output:
    • # sudo iptables -L -n
  6. And you can see that
    "ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:69"
    line is in the iptables file.

To block any particular port, you just need to edit /etc/sysconfig/iptables, remove the ACCEPT line that contain that port, and restart iptables, and you are done :)


Save IP tables on CentOS
/etc/init.d/iptables start or service iptables save


Remove IPtable rules by line
iptables -vnL --line-numbers
iptables -D INPUT 22


Friday, November 22, 2013

Set a static internal IP

1. find a hooked interface

2. make a script in /etc/sysconfig/network-scripts
For example:
$cd /etc/sysconfig/network-scripts
$touch ifcfg-em1
$vim ifcfg-em1

DEVICE=em1
HWADDR=A4:BA:DB:1A:AC:4F this is the mac address of the interface
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.27 this is the static IP you want to set
BROADCAST=192.168.0.255
NETMASK=255.255.255.0

NAME=em1

3. restart the device
$ ifdown em1
$ ifup em1

4. finally, check if the static ip has been assigned to interface em1
$ ifconfig

Check if the interface hook or not

$ yum install ethtool

$ ifconfig to see how may interfaces available

$ ethtool [Interface Name]

[root@sr2s7 home]# ethtool em1
Settings for em1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: g
        Wake-on: d

        Link detected: yes Means the link is hooked.

Wednesday, July 3, 2013

Enable networking in VENET OpenVZ container

I followed the instruction from OpenVZ website fo quickly create an VENET container, but it took me a while to enable networking.
Environment: CentOS 6.4 as the server, and try to create an centos-6-x86_64 container

Here is the instruction from OpenVZ website:

https://openvz.org/Quick_Installation_CentOS_6

Create a VENET Container

  • Create a CT
# vzctl create 101 --ostemplate centos-6-x86_64 --config vswap-1g
  • Configure the CT
# vzctl set 101 --save --name server101
# vzctl set 101 --save --onboot yes
# vzctl set 101 --save --hostname server101.example.com
# vzctl set 101 --save --ipadd 192.168.1.101
# vzctl set 101 --save --searchdomain example.com
# vzctl set 101 --save --nameserver 8.8.8.8 --nameserver 8.8.4.4
# vzctl set 101 --save --cpus 4
# vzctl set 101 --save --ram 8G
# vzctl set 101 --save --swap 4G
# vzctl set 101 --save --diskspace 100G
# vzctl start 101
# vzctl exec 101 passwd
  • Done. Enjoy your new VENET container



The instruction is correct, but there are 3 things you may want to pay attention.

1. set up a correct nameserver.
If you are setting up a real server, you can use command $dhclient, and it automatically identify the nameservers and write them into /etc/resovl.conf file. In OpenVZ container, we need to set it up manually.

2. use a correct IP.
In my case, I followed the instruction, and use IP address as 192.168.1.101, which causes me problem to connect to internet in the container. Then, I changed the IP address to 192.168.0.101, and the container can ping google successfully. I think this is because there are internal setting in my subnet, and they may have some IP restrictions.

3. set up a correct IP tables in host node.
Because I used Cent OS 6.4 as my host server, it has IP tables firewall enabled. One simpler solution is to run command $ iptables --flush, it clean all of the IP table rules, but it comes back after reboot. If you want to permanetly change the iptable settings, you need to add a rule to allow the connection from the container to the Internt.

Additionally, take read this page: https://openvz.org/Common_Networking_HOWTOs
My experiments have been working with private IP inaccessible from LAN (case 1) and public static IP accessible from the same LAN (case 2).

Note that, we need to change the interface name (run ifconfig to see which interface that connections to the outside on host) to run this command that enables ping google from the containers.
[host-node]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Monday, July 1, 2013

Some commands related to networking on Linux

Network Device Up and Down
$ service network restart
$ /etc/init.d/network restart

$ service network start
$ service network stop

$ifdown eth0
$ifup eth0

$ ifconfig

$ dhclient

Name Server
$ vim /ect/resolv.conf
[root@sr1s1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 129.174.97.3
nameserver 129.174.68.227
nameserver 129.174.1.3

HostName
$ echo hostname=$HOSTNAME >> /etc/sysconfig/network
set hostname

Routing Table
$ route
show the routing tables

IP Table
$ iptables --list
view all of the ip table rules

Opening Ports
$lsof -i

Start SSH
$ service sshd restart

Automatically Start SSH on Boot
$ chkconfig --level 5 --del sshd
$ chkconfig --level 5 --add sshd

Query system running service
$ chkconfig

Update bashrc or profile
$ source ~/.profile

Thursday, June 20, 2013

Change hostname on CentOS

$vim /etc/sysconfig/network

Change the HOSTNAME to anything you like
e.g.: sr1s5

Tuesday, April 23, 2013

List of Intel NICs

List of Intel Network Controller

http://www.intel.com/content/www/us/en/ethernet-controllers/ethernet-controllers.html

Intel® 82574 Gigabit Ethernet Controller

Intel® 82541 Gigabit Ethernet Controller

Intel® 82540 Gigabit Ethernet Controller

Monday, June 25, 2012

Packet Generator Tool

PackETH: ethernet packet generator
It can generate any raw packet.

Download from:
http://packeth.sourceforge.net/
http://sourceforge.net/projects/packeth/
The default file is for Windows, and Linux version need to Click on Browser all link

Install:
cd to packet directory
./configure
make
sudo make install

Usage:
Run it as root
Define packet header, payload, and interface, and click send

Saturday, December 3, 2011

ethtool

// man page of ethtool
$ ethtool -h

// Check statistic registers of network card
$ ethtool -S eth0

// See most of the registers of network card in interface eth0
$ ethtool -d eth0

// See the driver information
$ ethtool -i eth0

NIC: Intel e1000

more info:
http://www.globax.info/mediawiki/index.php/Intel_Gigabit_Performance

Friday, November 18, 2011

ifconfig commands

$ifconfig eth0 down

$ifconfig eth1 up

Thursday, November 17, 2011

tcpdump Howto

$ tcpdump -i eth0 -w outputfile // listen on interface eth0, and write all the traffic to outputfile, may need root privilege.

$ tcpdump -r outputfile > textfile // read the raw traffic and put it into textfile

tcpdump -r tcpdump2 -tt > textfile2 // flag -tt mean don't format the time

More: man tcpdump

Monday, November 7, 2011

Checksum offloading

software doesn't do checksum calcalation, it hand over an empty checksum field to the hardware and hardware does that automaticlly. 


Link:http://www.wireshark.org/docs/wsug_html_chunked/ChAdvChecksums.html


Recent network hardware can perform advanced features such as IP checksum calculation, also known as checksum offloading. The network driver won't calculate the checksum itself but will simply hand over an empty (zero or garbage filled) checksum field to the hardware.

Tuesday, April 26, 2011

Socket Programming in C (3): Socket to Address structure Translation

// Get address structure by sock on current side, E.g. you want to know the client port number which randomly assigned
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

// Get address structure by sock on the other side. E.g. server wants to know client's structure.
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);