IP linux command

Understanding ip command OBJECTS syntax OBJECTS can be any one of the following and may be written in full or abbreviated form:

  • Link: Network device (l)
  • address: Protocol (IP or IPv6) address on a device (a)
  • addrlabel: Label configuration for protocol address selection (addrl)
  • neighbour: ARP or NDISC cache entry (neigh)
  • route: Routing table entry (r)
  • rule: Rule in routing policy database (ru)
  • maddress: Multicast address (maddr)
  • mroute: Multicast routing cache entry (mr)
  • tunnel: Tunnel over IP (t)
  • xfrm: Framework for IPsec protocol (x)
ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help

You can select between IPv4 and IPv6 using the following syntax:

# Only show TCP/IP IPv4
ip -4 a

# Only show TCP/IP IPv6
ip -6 a

It is also possible to specify and list particular interface TCP/IP details:

# Only show eth0 interface
ip a show eth0
ip a list eth0
ip a show dev eth0

# Only show running interfaces
ip link show up

IP route add network command examples

ip route add {NETWORK/MASK} via {GATEWAYIP}
ip route add {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} dev {DEVICE}
ip route add default {NETWORK/MASK} via {GATEWAYIP}
Hello World

A sample go program is show here.

package main

import "fmt"

func main() {
  message := greetMe("world")
  fmt.Println(message)
}

func greetMe(name string) string {
  return "Hello, " + name + "!"
}

Run the program as below:

$ go run hello.go
Variables

Normal Declaration:

var msg string
msg = "Hello"

Shortcut:

msg := "Hello"
Constants
const Phi = 1.618
Tip et configuration
# test la configuration
varnishd -C -f /etc/varnish/default.vcl
# Request sur les logs
varnishlog -q "RespStatus == 503" -g request
varnishlog -g request
Examples
# filter for 503 errors
varnishlog -q "RespStatus == 503" -g request
varnishlog -g request

# filter by request host header
varnishlog -q 'ReqHeader ~ "Host: example.com"'

# filter by request url
varnishlog -q 'ReqURL ~ "^/some/path/"'

# filter by client ip (behind reverse proxy)
varnishlog -q 'ReqHeader ~ "X-Real-IP: .*123.123.123.123"'

# filter by request host header and show request url and referrer header
varnishlog -q 'ReqHeader ~ "Host: (www\.)?example\.com"' -i "ReqURL" -I "ReqHeader:Referer:"

# filter for permanent redirects and show request host/url and new location
varnishlog -q "RespStatus ~ 301" -i "ReqURL" -I "ReqHeader:Host:" -I "RespHeader:Location:" -i "RespStatus"

# filter for permanent and temporary redirects and filter for Location "http://s3" to
# just show (for example) redirects to something on an Amazon S3 bucket
varnishlog -q '(RespStatus ~ 301 or RespStatus ~307) and RespHeader ~ "Location: https://s3"' \
   -i "ReqURL" -I "ReqHeader:Host:" -I "RespHeader:Location:" -i "RespStatus" -I "ReqHeader:Referer:"
Gestion des 503
vcl 4.0;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    if (req.url ~ "^/404") {
        return (synth(999, "make 404 error explicitly"));
    }
}

sub vcl_backend_response {
}

sub vcl_deliver {
}

sub vcl_backend_error {
    set beresp.http.Content-Type = "text/html; charset=utf-8";
    synthetic( {"errors due to backend fetch"} );
    return (deliver);
}

sub vcl_synth {
    if (resp.status == 999) {
        set resp.status = 404;
        set resp.http.Content-Type = "text/plain; charset=utf-8";
        synthetic({"errors due to vcl"});
        return (deliver);
    }
    return (deliver);
}