Saturday, February 22, 2020

understanding bgp regex

Hi Brian,
Can you explain the easiest way to construct a regular expression in BGP?
Thanks,
Rowan
Hi Rowan,
Regular expressions are strings of special characters that can be used to search and find character patterns. Within the scope of BGP in Cisco IOS regular expressions can be used in show commands and AS-Path access-lists to match BGP prefixes based on the information contained in their AS-Path.
In order to understand how to build regular expressions we first need to know what the character definitions are for the regex function of IOS. The below table illustrates the regex characters and their usage. This information is contained in the Cisco IOS documentation under the Appendix of Cisco IOS Terminal Services Configuration Guide, Release 12.2.
+------------------------------------------------------+

| CHAR | USAGE                                         |

+------------------------------------------------------|

|  ^   | Start of string                               |

|------|-----------------------------------------------|

|  $   | End of string                                 |

|------|-----------------------------------------------|

|  []  | Range of characters                           |

|------|-----------------------------------------------|

|  -   | Used to specify range ( i.e. [0-9] )          |

|------|-----------------------------------------------|

|  ( ) | Logical grouping                              |

|------|-----------------------------------------------|

|  .   | Any single character                          |

|------|-----------------------------------------------|

|  *   | Zero or more instances                        |

|------|-----------------------------------------------|

|  +   | One or more instance                          |

|------|-----------------------------------------------|

|  ?   | Zero or one instance                          |

|------|-----------------------------------------------|

|  _   | Comma, open or close brace, open or close     |

|      | parentheses, start or end of string, or space |

+------------------------------------------------------+
Some commonly used regular expressions include:
+-------------+---------------------------+

| Expression  | Meaning                   |

|-------------+---------------------------|

| .*          | Anything                  |

|-------------+---------------------------|

| ^$          | Locally originated routes |

|-------------+---------------------------|

| ^100_       | Learned from AS 100       |

|-------------+---------------------------|

| _100$       | Originated in AS 100      |

|-------------+---------------------------|

| _100_       | Any instance of AS 100    |

|-------------+---------------------------|

| ^[0-9]+$    | Directly connected ASes   |

+-------------+---------------------------+
Let’s break some of the above expressions down step-by-step. The first one “.*” says to match any single character (“.”), and then find zero or more instances of that single character (“*”). This means zero or more instances or any character, which effectively means anything.
The next string “^$” says to match the beginning of the string (“^”), and then immediately match the end of the string (“$”). This means that the string is null. Within the scope of BGP the only time that the AS-Path is null is when you are looking at a route within your own AS that you or one of your iBGP peers has originated. Hence this matches locally originated routes.
The next string “^100_” says to match the beginning of the string (“^”), the literal characters 100, and then a comma, an open or close brace, an open or close, a parentheses, the start or end of the string, or a space (“_”). This means that the string must start with the number 100 followed by any non-alphanumeric character. In the scope of BGP this means that routes which are learned from the AS 100 will be matched, as 100 will be the first AS in the path when AS 100 is sending us routes.
The next string “_100$” is the exact opposite of the previous one. This string says to start with any non-alphanumeric character (“_”), followed by the literal characters 100, followed by the end of the string (“$”). This means that AS 100 is the last AS in the path, or in other words that the prefix in question was originated by AS 100.
The next string “_100_” is the combination of the two previous strings with some extra matches. This string means that the literal characters 100 are set between any two non-alphanumeric characters. The first of these could be the start of the string, which would match routes learned from AS 100, while the second of these could be the end of the string, which would match routes originated in AS 100. Another case could be that the underscores represent spaces, in which the string would match any other AS path information as long as “ 100 ” is included somewhere. This would match any routes which transit AS 100, and therefore “_ASN_” is generally meant to match routes that transit a particular AS as defined by the number “ASN”.
The final string “^[0-9]+$” is a little more complicated match. Immediately we can see that the string starts (“^”), and we can see later that it ends (“$”). In the middle we see a range of numbers 0-9 in brackets, followed by the plus sign. The numbers in brackets mean that any number from zero to nine can be matched, or in other words, any number. Next we have the plus sign which means one or more instances. This string “[0-9]+” therefore means one or more instance of any number, or in other words any number including numbers with multiple characters (i.e. 1, 12, 123, 1234, 12345678, etc.). When we combine these all together this string means routes originated in any directly connected single AS, or in other words, the routes directly originated by the peers of your AS.
Now let’s look at a more complicated match, and using the above character patterns we will see how we can construct the expression step by step. Suppose we have the following topology below, where we are looking at the network from the perspective of AS 100.
+--------+ +--------+ +--------+ +--------+

| AS 200 |-| AS 201 |-| AS 202 |-| AS 203 |\

+--------+ +--------+ +--------+ +--------+ \

                                             \

           +--------+ +--------+ +--------+\  \

           | AS 300 |-| AS 301 |-| AS 302 | \  \

           +--------+ +--------+ +--------+  \  -+--------+

                                              >--| AS 100 |

                      +--------+ +--------+  /  -+--------+

                      | AS 400 |-| AS 401 | /  /

                      +--------+ +--------+/  /

                                             /

                                 +--------+ /

                                 | AS 500 |/

                                 +--------+
AS 100 peers with ASes 203, 302, 401, and 500, who each have peers as diagramed above. AS 100 wants to match routes originated from its directly connected customers (ASes 203, 302, 401, and 500) in addition to routes originated from their directly connected customers (ASes 202, 301, and 400). The easiest way to create this regular expression would be to think about what we are first trying to match, and then write out all possibilities of these matches. In our case these possibilities are:
203

203 202

302

302 301

401

401 400

500
Now we could simply create an expression with multiple lines (7 lines to be exact) that would match all of the possible AS paths, but suppose that AS 100 wants to keep this match as flexible as possible so that it will apply to any other ASes in the future. Now let’s try to generalize the above AS-Path information into a regex.
First off we know that each of the matches is going to start and going to end. This means that the first character we will have is “^” and the last character is “$”. Next we know that between the “^” and “$” there will be either one AS or two ASes. We don’t necessarily know what numbers these ASes will be, so for the time being let’s use the placeholder “X”. Based on this our new possible matches are:
^X$

^X X$
Next let’s reason out what X can represent. Since X is only one single AS, there will be no spaces, commas, parentheses, or any other special type characters. In other words, X must be a number. However, since we don’t know what the exact path is, we must take into account that X may be a number with more than one character (i.e. 10, 123, or 10101). This essentially equates to one or more instance of any number zero through nine. In regular expression syntax our two matches would therefore now read:
^[0-9]+$

^[0-9]+ [0-9]+$
This expressions reads that we either have a number consisting of one or more characters zero through nine, or a number consisting of one or more characters zero through nine followed by a space and then another number consisting of one or more characters zero through nine. This brings our expression down to two lines as opposed to our original seven, but let’s see how we can combine the above two as well. To combine them, first let us compare what is different between them.
^[0-9]+$

^[0-9]+ [0-9]+$
From looking at the expressions it is evident that the sequence “ [0-9]+” is the difference. In the first case “ [0-9]+” does not exist in the expression. In the second case “ [0-9]+” does exist in the expression. In other words, “ [0-9]+” is either true or false. True or false (0 or 1) is represented by the character “?” in regex syntax. Therefore we can reduce our expression to:
^[0-9]+ [0-9]+?$
At this point we run into a problem with the order of operations of the regex. As denoted above the question mark will apply only to the plus sign, and not to the range [0-9]. Instead, we want the question mark to apply to the string “ [0-9]+” as a whole. Therefore this string needs to be grouped together using parentheses. Parentheses are used in regular expressions as simply a logical grouping. Therefore our final expression reduces to:
^[0-9]+( [0-9]+)?$
Note that to match a question mark in IOS, the escape sequence CTRL-V or ESC-Q must be entered first, otherwise the IOS parser will interpret the question mark as an attempt to invoke the context sensitive help.

bash completion pada centos7

Kali ini saya akan nyimpen catetan enable bash-completion di centos7. Sebagaimana kita tahu, untuk mencari file itu menggunakan perintah locate namafile
Tapi sebelumnya harus install locate pada debian, kl di centos namanya mlocate.
Baiklah, langsung saja begini caranya
[root@server ~]# yum install bash-completion bash-completion-extras -y
[root@server ~]# yum install mlocate -y
[root@server ~]# updatedb
[root@server ~]# locate bash_completion.sh
[root@server ~]# locate bash_completion.sh
/etc/profile.d/bash_completion.sh
[root@server ~]# source /etc/profile.d/bash_completion.sh 
[root@server ~]# logout 
jika sudah, coba lakukan yum install [tab]
disana tertera semua perintah lanjutan.

Monday, February 17, 2020

install mysql-server di centos

install mysql-server di centos
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server -y
systemctl start mysqld
systemctl status mysqld
clear
grep 'temporary password' /var/log/mysqld.log | awk '{print "password mysql: " $13}'
echo "silahkan diganti dengan command mysql_secure_installation"

Wednesday, February 12, 2020

prepare frr

    1  ip addr
    2  nano /etc/network/interfaces
    3  nano /etc/apt/sources.list

#deb cdrom:[Debian GNU/Linux 10.0.0 _Buster_ - Official amd64 xfce-CD Binary-1 20190706-10:24]/ buster main
deb http://deb.debian.org/debian/ buster main contrib non-free
deb-src http://deb.debian.org/debian/ buster main contrib non-free
deb http://security.debian.org/debian-security buster/updates main contrib non-free
deb-src http://security.debian.org/debian-security buster/updates main contrib non-free
deb http://deb.debian.org/debian/ buster-backports main contrib non-free
deb-src http://deb.debian.org/debian/ buster-backports main contrib non-free
# buster-updates, previously known as 'volatile'
# A network mirror was not selected during install.  The following entries
# are provided as examples, but you should amend them as appropriate
# for your mirror of choice.
#
# deb http://deb.debian.org/debian/ buster-updates main
# deb-src http://deb.debian.org/debian/ buster-updates main
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
    4  apt update
    5  ping 1.1.1.1
    6  nano /etc/resolv.conf
    7  apt update
    8  apt dist-upgrade
    9  tasksel
   10  clear
   11  apt install intel-microcode
   12  apt install sudo
   13  apt dist-upgrade
   14  clear
   15  apt install build-essentials
   16  apt install build-essential
   17  apt-cache search bird
   18  apt-cache search bird | more
   19  apt install tuned
   20  apt install iftop iptraf htop bwm-ng
   21  apt install strace
   22  nano /etc/sysctl.conf
   23  nano /etc/apt/sources.list
   24  apt update
   25  nano /etc/apt/sources.list
   26  apt update
   27  nano /etc/apt/sources.list
   28  apt update
   29  nano /etc/apt/sources.list
   30  apt update
   31  apt dist-upgrade
   32  apt install linux-image
   33  apt cache search kernel
   34  apt-cache search kernel
   35  apt-cache search linux-image
   36  apt-cache search linux-image-amd64
   37  apt-cache search linux-image-5.3.0-amd64
   38  apt install linux-image-amd64
   39  apt install linux-image-5.6.0-0.bpo.2-amd64
   40  apt install linux-image-5.3.0-0.bpo.2-amd64
   41  apt install linux-headers-5.3.0-0.bpo.2-amd64
   42  adduser bitbox sudo
   43  cd /home/bitbox/
   44  ls
   45  cp -R * /etc/systemd/network/
   46  cd /etc/systemd/network/
   47  ls
   48  nano 11-sfplus1.link
   49  update-initramfs -c -k all
   50  reboot
   51  ip addr
   52  nano /etc/network/interfaces
   53  reboot
   54  apt install ifenslave
   55  apt install bridge-utils
   56  nano /etc/resolv.conf
   57  ping 1.1.1.1
   58  ip r
   59  ip route replace default via 192.168.99.254
   60  ip r
   61  apt update
   62  apt dist-upgrade
   63  ip r
   64  apt install bridge-utils
   65  brctl show
   66  apt update
   67  apt install ifupdown2
   68  apt install vlan
   69  vconfig
   70  ip link
   71  nano /etc/network/interfaces
   72  apt update
   73  apt update
   74  nano /etc/network/interfaces
   75  nano /etc/ssh/sshd_config
   76  systemctl restart sshd
   77  reboot
   78  ip addr
   79  ip addr
   80  nano /etc/network/interfaces
   81  ip addr
   82  ip addr add 192.168.99.1/24 dev ge1
   83  ip r
   84  ip r
   85  ip addr
   86  ip link ge1 up
   87  ip link set ge1 up
   88  ip addr
   89  ip r
   90  ip route add default via 192.168.99.1
   91  apt update
   92  apt dist-upgrade
   93  apt install bird
   94  bird -c
   95  apt autoremove bird
   96  apt install bird2
   97  apt-cache search bird2
   98  apt-cache search bird
   99  apt install bird-bgp
  100  apt autoremove bird-bgp
  101  apt autoremove bird-bgp
  102  wget -O - http://bird.network.cz/debian/apt.key | apt-key add -
  103  apt-get install lsb-release
  104  echo "deb http://bird.network.cz/debian/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/bird.list
  105  apt update
  106  wget -O - http://bird.network.cz/debian/apt.key |
  107  apt-secure
  108  apt-key add
  109  ls
  110  ls
  111  wget -c ftp://bird.network.cz/pub/bird/debian/apt.key
  112  lls
  113  ls
  114  apt-key add apt.key
  115  apt update
  116  apt install debian-keyring
  117  apt-key add apt.key
  118  apt update
  119  apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B188E2B695BD4743
  120  apt update
  121  apt upgrade
  122  apt install bird
  123  bird -c
  124  bird --version
  125  apt-cache search bird2
  126  apt autoremove bird
  127  apt install bird2
  128  clear
  129  bird --version
  130  clear
  131  tuned-adm profile
  132  tuned-adm profile network-latency
  133  tuned-adm profile network-troughput
  134  tuned-adm profile network-throughput
  135  htop
  136  clear
  137  apt dist-upgrade
  138  free -m
  139  vgs
  140  lvs
  141  swapoff -a
  142  swapon -a
  143  free -m
  144  clear
  145  bwm-ng
  146  apt install ifupdown2
  147  ip addr
  148  nano /etc/network/on
  149  nano /etc/network/interfaces
  150  reboot
  151  iperf3 -c localhost
  152  tuned-adm profile network-latency
  153  iperf3 -c localhost
  154  htop
  155  iperf3 -c localhost
  156  ping localhost
  157  tuned-adm profile network-throughput
  158  ping localhost
  159  brctl show
  160  vlan
  161  vconfig
  162  ip addr
  163  ethtool -m sfplus4
  164  ethtool -i sfplus4
  165  apt update
  166  apt dist-upgrade
  167  cd /usr/src/
  168  ls
  169  tar -xzvf i40e-2.10.19.30.tar.gz
  170  ls
  171  cd i40e-2.10.19.30/
  172  ls
  173  cd src/
  174  ls
  175  make
  176  make install
  177  htop
  178  bwm-ng
  179  bwm-ng
  180  iperf3 -c
  181  iperf3 -c localhost
  182  apt install python3 pip
  183  apt install python3-pip
  184  pip3-install speedtest-cli
  185  pip3 install speedtest-cli
  186  speedtest-cli
  187  ip addr
  188  ip link set add ge1
  189  ip link add link ge1 name ge1.100 type vlan id 100
  190  ip addr
  191  lsmod
  192  lsmod | grep 802
  193  exit
  194  vconfig show
  195  vconfig show
  196  vconfig
  197  apt update
  198  ip addr
  199  ifquery --all
  200  ifquery
  201  ifquery -a
  202  ifquery --help
  203  ifquery -ra
  204  ifquery -r
  205  ip addr add 192.168.100.1/24 dev ge1.100
  206  ifquery -ra
  207  ifquery -r
  208  ip add
  209  htop
  210  top
  211  ip addr
  212  ethtool -m sfplus4
  213  ethtool -i sfplus4
  214  reboot
  215  apt install iperf3
  216  lksctp-tools
  217  iperf3 localhost
  218  iperf3 -s
  219  ethtool -i sfplus4
  220  ethtool -m sfplus4
  221  ethtool -m sfplus3
  222  ethtool -i sfplus3
  223  ethtool -i sfplus4
  224  ethtool -m sfplus4
  225  ethtool -m sfplus4
  226  ethtool -m sfplus3
  227  apt dist-upgrade
  228  nano /etc/default/grub
  229  nano /etc/default/grub
  230  update-grub
  231  nano /etc/motd
  232  reboot
  233  clear
  234  ip addr
  235  nano /etc/motd
  236  apt update
  237  tuned-adm
  238  tuned-adm profile
  239  tuned-adm active
  240  clear
  241  apt install intel-microcode
  242  free -m
  243  df -mh
  244  htop
  245  date
  246  dpkg-reconfigure tzdata
  247  clear
  248  update
  249  upate
  250  apt install command-not-found
  251  apt-file update
  252  update-command-not-found
  253  apt install lldpd
  254  lm-sensors snmp-mibs-downloader snmpd
  255  apt install lm-sensors snmp-mibs-downloader snmpd
  256  apt install unzip
  257  apt install zip
  258  clear
  259  dig
  260  apt install dns-utils
  261  apt update
  262  ps ax | more
  263  ip addr
  264  lldpc
  265  lldpcli
  266  debugfs
  267  poweroff
  268  ip addr
  269  poweroff
  270  poweroff
  271  vtysh
  272  exit
  273  vtysh
  274  ip addr | more
  275  ping 10.146.146.6
  276  ping 10.146.146.5
  277  ping 10.146.146.5
  278  ping 10.146.146.6
  279  arp -a
  280  apt install net-tools
  281  arp -a
  282  arp -a
  283  ifconfig ge8
  284  clear
  285  ip addr
  286  ip addr
  287  ip addr | more
  288  ip addr add 192.168.0.15/24 dev ge8
  289  ping 192.168.0.2
  290  ip link set ge8 up
  291  ping 192.168.0.2
  292  ping 192.168.0.15
  293  ping 192.168.0.8
  294  ping 192.168.0.2
  295  ip r
  296  ip route replace default via 192.168.0.2
  297  cat /etc/resolv.conf
  298  apt update
  299  apt dist-upgrade
  300  apt instal frr
  301  apt install frr
  302  systemctl stop bird
  303  systemctl stop bird6
  304  systemctl disable bird
  305  systemctl disable bird6
  306  frr --version
  307  vtysh
  308  apt autoremove frr
  309  cd /
  310  curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add -
  311  apt install curl
  312  apt install dudo
  313  apt install sudo
  314  curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add -
  315  FRRVER="frr-stable"
  316  echo deb https://deb.frrouting.org/frr $(lsb_release -s -c) $FRRVER | sudo tee -a /etc/apt/sources.list.d/frr.list
  317  sudo apt update && sudo apt install frr frr-pythontools
  318  vtysh
  319  nano /etc/frr/daemons
  320  nano /etc/sysctl.conf
  321  clear
  322  systemctl restart frr
  323  vtysh
  324  bwm-ng
  325  vtysh
  326  lldpcli
  327  vtysh
  328  vtysh
  329  uname -a
  330  apt install ffr
  331  apt install frr
  332  nano /etc/frr/daemons
  333  systemctl restart frr
  334  nano /etc/frr/vtysh.conf
  335  nano /etc/frr/frr.conf
  336  vtysh
  337  ifconfig
  338  ifconfig
  339  ip addr
  340  nano /etc/network/interfaces
  341  vytsh
  342  vtysh
  343  bwm-ng
  344  iftop -i ge8
  345  clear
  346  iftop -i ge8
  347  bwm-ng
  348  iptraf-ng
  349  sh run
  350  ip addr
  351  ip link add ge8 name ge8.100 type vlan vlan id 100
  352  ip link add ge8 name ge8.100 type vlan id 100
  353  ip link add name ge8.100 type vlan id 100
  354  modprobe 8021q
  355  ip link add name ge8.100 type vlan id 100
  356  vconfig
  357  vconfig add ge8 100
  358  vconfig show
  359  ip addr
  360  ifquery --show
  361  ifquery --running
  362  ifquery --running -a
  363  ifquery --running -a
  364  nano /etc/network/interfaces
  365  vconfig
  366  vconfig add ge8 101
  367  ip addr
  368  ifquery --running -a
  369  vtysh
  370  ip r
  371  ip r | wc -l
  372  exit
  373  vytsh
  374  vtysh
  375  do sh run
  376  vtysh
  377  vconfig
  378  vconfig rem ge8.100
  379  vconfig rem ge8.101
  380  vconfig show
  381  ip addr
  382  ifquery -a --running
  383  cat /etc/frr/frr.conf
  384  nano /etc/network/interfaces
  385  cat /etc/frr/frr.conf
  386  vytsh
  387  vtysh
  388  nano /etc/network/interfaces
  389  vtysh
  390  ip addr
  391  ip addr del 192.168.0.15/24 dev ge8
  392  vtysh
  393  ip addr del 192.168.0.15/24 dev ge7
  394  nano /etc/network/interfaces
  395  nano /etc/frr/frr.conf
  396  vtysh
  397  exit
  398  exit
  399  shutdown now
  400  nano /etc/frr/frr.conf
  401  nano /etc/network/interfaces
  402  vtysh
  403  exit
  404  cat /etc/frr/frr.conf
  405  exit
  406  shutdown now
  407  htop
  408  cat /proc/cpuinfo
  409  lscpu
  410  htop
  411  exit
  412  history