Sending packets out of incoming interface

It is desirable, in some circumstances on a server with multiple NIC’s to send outgoing traffic on incoming interface. In order to do so the server has to have policy routing implemented.

Let’s assume that the server is running CentOS 6 and that there are two network interfaces as follows:

Here is a simple example. First create routing table /etc/iproute2/rt_tables:

50 internal1
60 internal2

Names internal1 and internal2 are just random names. Now, create /etc/sysconfig/network-scripts/rule-eth0 which just defines under which circumstances routing table should be used:

iif eth0 table internal1
from table internal1

Next, define a rule for the second network interface /etc/sysconfig/network-scripts/rule-eth1as follows:

iif eth1 table internal2
from table internal2

Next, define route to using eth0 interface. The following lines go into /etc/sysconfig/network-scripts/route-eth0: dev eth0 table internal1
default via dev eth0 table internal1

And the same thing needs to be done for the second interface – eth1. The following lines need to be placed in /etc/sysconfig/network-scripts/route-eth1: dev eth1 table internal2
default via dev eth0 table internal2

Finally, remove GATEWAY stanza from /etc/sysconfig/network. That’s it. This will persist reboots as well.

Posted on September 3, 2017 at 10:39 by somedude · Permalink · Leave a comment
In: centos, linux, linux tips, networking, redhat, Uncategorized

Using whole disk for LVM during kickstart

I was kickstarting a machine that needed two disks. The requirement was that the second disk was to be used as whole for LVM. It seemed there was no way to do so, but apparently there is. The snippet below makes it happen. The key part is –onpart=sdb.

part pv.02 --grow --size=1 --onpart=sdb
volgroup vg_data --pesize=4096 pv.02
logvol /data --fstype=xfs --name=lv_data --vgname=vg_data --grow --size=1

Posted on August 31, 2017 at 09:15 by somedude · Permalink · Leave a comment
In: centos, kickstart, linux, linux tips, redhat

Another take on Dynamic Volume Resize in RHEL 6

Being able to resize an LVM volume without reboot is quite handy. I had described one way here. This is a slightly different take on the same topic, this time on RHEL 6.

I had resized /dev/sdb from 48GB to 140GB in vCenter. However, the operating system is still seeing the old size:

[root@build ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 48.3 GB, 48318382080 bytes
64 heads, 32 sectors/track, 46080 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000a

To get RHEL to see the new size, device rescan is needed:

[root@build ~]# cd /sys/class/block/sdb/device
[root@build ~]# echo "- - -" > rescan

The difference this time is that you do not need to look for the correct HBA and LUN number. You can just go by the device name. Now the operating system should see the correct disk size:

[root@build device]# fdisk -l /dev/sdb
Disk /dev/sdb: 198.6 GB, 198642237440 bytes
255 heads, 63 sectors/track, 24150 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Now you can proceed with resizing the physical volume and the logical volume. You can throw in -t switch to do a dry run:

[root@build device]# pvresize /dev/sdb
  Physical volume "/dev/sdb" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
[root@build device]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  system lvm2 a--   19.47g   3.00g
  /dev/sdb   vg_app lvm2 a--  185.00g 140.00g

The size is correct now. Finally, resize the logical volume. Again, you can throw in -t switch to do a dry run:

[root@build device]# lvresize -r -l+100%FREE /dev/mapper/vg_app-lv_app
  Size of logical volume vg_app/lv_app changed from 45.00 GiB (11519 extents) to 140.00 GiB (35840 extents).
  Logical volume lv_app successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_app-lv_app is mounted on /var/www/html/repo; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 9
Performing an on-line resize of /dev/mapper/vg_app-lv_app to 36700160 (4k) blocks.
The filesystem on /dev/mapper/vg_app-lv_app is now 36700160 blocks long.


Posted on December 17, 2013 at 09:37 by somedude · Permalink · Leave a comment
In: centos, fibre channel, linux, linux tips, lvm2, san, storage

There is no screen to be resumed…

I was running a script on a server that took a while to complete. Since I did not want to lose any output I ran it inside a screen session. Of course, during the course of this, my SSH connection dropped and when I logged in again, and tried to reattached to the session I got this:

[root@ultra ~]# screen -list
There is a screen on:
21884.pts-0.ultra (Attached)
1 Socket in /var/run/screen/S-root.
[root@ultra ~]# screen -r 21884.pts-0.ultra
There is a screen on:
21884.pts-0.ultra (Attached)
There is no screen to be resumed matching 21884.pts-0.ultra.

As it turns out, you have I had to first detach and logout first, to be able to attach to the session:

[root@ultra ~]# screen -D -r 21884.pts-0.ultra

Useful to know…

Posted on November 15, 2013 at 08:56 by somedude · Permalink · Leave a comment
In: linux, linux tips, linux utilities, screen, shell

Hung Linux system: Now what?

Finally, I had remembered to try out Magic SysRq key in real life. One of the XenServer hosts decided to refuse to reboot and hung during shutdown. Magic SysRq is really a keyboard combo that allows user to force kernel to perform certain function, even though machine is unresponsive. In my case I needed to safely reboot the host.

For Magic SysRq to work, it must be enabled in kernel:

[root@db0004 ~]# cat /proc/sys/kernel/sysrq

If output is 1, then you are good to go. Thankfully, XenServer had this enabled. So, while holding down Alt and SysRq keys I pressed the following keys: r e i s u b.

So, what do all the letters mean? I ripped the explanation from Wikipedia. Article is worth checking out, especially the section on how to deal with keyboards other than QWERTY.

    r : Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE mode
    e : Send the SIGTERM signal to all processes except init (PID 1)
    i : Send the SIGKILL signal to all processes except init
    s : Sync all mounted filesystems
    u : Remount all mounted filesystems in read-only mode
    b : Immediately reboot the system, without unmounting or syncing filesystems

The Wikipedia article also mentions couple of mnemonics to help remembering the key sequence.

Posted on October 30, 2013 at 09:04 by somedude · Permalink · Leave a comment
In: centos, linux, linux tips, redhat