Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Thursday, October 11, 2012

Find list of open ports / listening ports


lsof

Samples 
 # lsof -i -n -P

netstat

Samples
# netstat -tulpn
# netstat -a | egrep 'Proto|LISTEN'
# netstat -ao

Important netstat arguments
-n, --numeric           don't resolve names - this one really saves time ;)
-e, --extend            display other/more information
-p, --programs          display PID/Program name for sockets
-l, --listening         display listening server sockets
-t, --tcp   tcp
-u, --udp   udp
-a, --all, --listening  display all sockets (default: connected)
-c, --continuous        continuous listing 

Sunday, August 26, 2012

Centos - Configuring network interfaces


Taken from - http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-networkscripts-interfaces.html



13.2.1. Ethernet Interfaces


One of the most common interface files is ifcfg-eth0, which controls the first Ethernet network interface card or NIC in the system. In a system with multiple NICs, there are multiple ifcfg-eth<X> files (where<X> is a unique number corresponding to a specific interface). Because each device has its own configuration file, an administrator can control how each interface functions individually.
The following is a sample ifcfg-eth0 file for a system using a fixed IP address:
DEVICE=eth0 
BOOTPROTO=none 
ONBOOT=yes 
NETWORK=10.0.1.0 
NETMASK=255.255.255.0 
IPADDR=10.0.1.27 
USERCTL=no
The values required in an interface configuration file can change based on other values. For example, the ifcfg-eth0 file for an interface using DHCP looks different because IP information is provided by the DHCP server:
DEVICE=eth0 
BOOTPROTO=dhcp 
ONBOOT=yes
The Network Administration Tool (system-config-network) is an easy way to make changes to the various network interface configuration files (refer to Chapter 14, Network Configuration for detailed instructions on using this tool).
However, it is also possible to manually edit the configuration files for a given network interface.
Below is a listing of the configurable parameters in an Ethernet interface configuration file:
BOOTPROTO=<protocol>
where <protocol> is one of the following:
  • none — No boot-time protocol should be used.
  • bootp — The BOOTP protocol should be used.
  • dhcp — The DHCP protocol should be used.
BROADCAST=<address>
where <address> is the broadcast address. This directive is deprecated, as the value is calculated automatically with ifcalc.
DEVICE=<name>
where <name> is the name of the physical device (except for dynamically-allocated PPP devices where it is the logical name).
DHCP_HOSTNAME
Use this option only if the DHCP server requires the client to specify a hostname before receiving an IP address.
DNS{1,2}=<address>
where <address> is a name server address to be placed in /etc/resolv.conf if the PEERDNS directive is set to yes.
ETHTOOL_OPTS=<options>
where <options> are any device-specific options supported by ethtool. For example, if you wanted to force 100Mb, full duplex:
ETHTOOL_OPTS="autoneg off speed 100 duplex full"

Note

Changing speed or duplex settings almost always requires disabling autonegotiation with the autoneg off option. This needs to be stated first, as the option entries are order-dependent.
GATEWAY=<address>
where <address> is the IP address of the network router or gateway device (if any).
HWADDR=<MAC-address>
where <MAC-address> is the hardware address of the Ethernet device in the formAA:BB:CC:DD:EE:FF. This directive is useful for machines with multiple NICs to ensure that the interfaces are assigned the correct device names regardless of the configured load order for each NIC's module. This directive should not be used in conjunction with MACADDR.
IPADDR=<address>
where <address> is the IP address.
MACADDR=<MAC-address>
where <MAC-address> is the hardware address of the Ethernet device in the formAA:BB:CC:DD:EE:FF. This directive is used to assign a MAC address to an interface, overriding the one assigned to the physical NIC. This directive should not be used in conjunction with HWADDR.
MASTER=<bond-interface>
where <bond-interface> is the channel bonding interface to which the Ethernet interface is linked.
This directive is used in conjunction with the SLAVE directive.
Refer to Section 13.2.3, “Channel Bonding Interfaces” for more information about channel bonding interfaces.
NETMASK=<mask>
where <mask> is the netmask value.
NETWORK=<address>
where <address> is the network address. This directive is deprecated, as the value is calculated automatically with ifcalc.
ONBOOT=<answer>
where <answer> is one of the following:
  • yes — This device should be activated at boot-time.
  • no — This device should not be activated at boot-time.
PEERDNS=<answer>
where <answer> is one of the following:
  • yes — Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default.
  • no — Do not modify /etc/resolv.conf.
SLAVE=<bond-interface>
where <bond-interface> is one of the following:
  • yes — This device is controlled by the channel bonding interface specified in the MASTER directive.
  • no — This device is not controlled by the channel bonding interface specified in the MASTERdirective.
This directive is used in conjunction with the MASTER directive.
Refer to Section 13.2.3, “Channel Bonding Interfaces” for more about channel bonding interfaces.
SRCADDR=<address>
where <address> is the specified source IP address for outgoing packets.
USERCTL=<answer>
where <answer> is one of the following:
  • yes — Non-root users are allowed to control this device.
  • no — Non-root users are not allowed to control this device.

Where are my file /etc/network/interfaces [centos]



What you're looking for is more likely /etc/sysconfig/network-scripts/ifcfg-eth*.... it has been like this in CentOS 5.2 also.

Ubuntu (deb) - /etc/network/interfaces
Centos (rpm) - /etc/sysconfig/network-scripts/ifcfg-eth*


CentOS 6.3


Q: From where does ifconfig shows eth0, eth1... , where are they defined?
Listing of eth0, eth1... are in file /etc/udev/rules.d/70-persistent-net.rules
* It is safe to remove lines from 70-persistent-net.rules
This file is recreated from the ifcfg-eth* files inside directory /etc/sysconfig.network-scripts if they contain onboot=1



Host-Only Networking With VirtualBox


Taken from - http://christophermaier.name/blog/2010/09/01/host-only-networking-with-virtualbox


I’ve been playing around with VirtualBox lately, and it’s pretty nifty. Initially I just used it to set up an Ubuntu machine so I could easily run GnuCash on my MacBook, but lately I’ve decided to start using it at work, too. I’ve got lots of plans: figure out how to use Chef, set up my own Hudsonserver, get a MongoDB cluster running, etc. I’d like all of these machines to be able to access the internet for downloading packages and the like, and I also want to be able to access them easily from my host machine. I don’t want these servers to be accessible from anywhere else on the network, however; these are just for me to experiment with for the time being. After banging my head on this for a little while, I think I’ve finally hit upon a (the?) solution.
Just for completeness’ sake, my host is Mac OS X and my guests are all Ubuntu boxes, so any system-specific instructions here are going to have a UNIX orientation. You have been warned.

Step 1: Access the Internet from the Guest

Set up one of your guest machine’s networking adapters to NAT. This is really easy, since it’s the default.
This will allow the guest system to access the broader internet through your host’s connection. You’ll be able to download packages, check email; whatever. Nobody outside sees anything of your guest system; as far as they’re concerned, it doesn’t exist. However, you cannot access any guest resources from your host machine, nor can any guest machines access each other. Yet.

Step 2: Access the Guest from the Host (and Other Guests)

We’ll need to add another network adapter to your guest machine, but this time, it’ll be a Host-Only Adapter. By using this type of adapter, you’ll be able to access a private, virtual network consisting solely of your host and any guests. Any of the member machines can access each other, but nothing outside of this self-contained “network in a box” can get in.
VirtualBox can create several of these virtual host-only networks (it’s what the “Name” field refers to in the Network Adapter Setup screen above). You can configure these in the VirtualBox Preferences; there should be one already created for you called vboxnet0 network.
Click on the “Edit” button for your Host-only network; you’ll see a dialog like this:
Take note of the adapter’s IP address (192.168.56.1 here); that’s the address at which your guests can access the host.
By default, there’s a DHCP server set up on the network. Since we’re going to be assigning static IP addresses, we don’t really need this, so you can uncheck the “Enable Server” box on the DHCP configuration panel.

Step 3: Configure Guests

We need each of the guests to have a static IP address on the host-only network. Log in to your Ubuntu guest and issue the following command:
ifconfig eth1 192.168.56.101 netmask 255.255.255.0 up
(Use whatever IP on your host-only network you like, of course.) This binds a network interface to one of the IP addresses on your host-only network (eth0 was bound to the NAT adapter). Now you should be able to SSH into your guest from your host (for example) using this IP address.
This is just temporary, however; once you reboot, this configuration will disappear. To make it permanent, add this to your /etc/network/interfaces file (as root):
# The host-only network interface
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
Reboot, and this interface should now show up when you type ifconfig.

Step 4: Make Networking Easier with /etc/hosts

Remembering IP addresses is a pain; we’d much rather use machine names. Fortunately, we don’t need to bother with a DNS server, since /etc/hosts makes this trivial. Just edit the file (as root) adding lines like the following:
192.168.56.101    myserver1
192.168.56.102    myserver2
… and so on. You can do this on the host as well as on the guests. This makes it really simple to access any machine on the host-only network. Now you can just do something like ssh myserver1instead of ssh 192.168.56.101.
And that ought to do it.