diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index 4710bfba..76495a07 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -1727,9 +1727,13 @@ bgp_update_attrs(struct bgp_proto *p, struct bgp_channel *c, rte *e, ea_list *at
     bgp_set_attr_ptr(&attrs, pool, BA_AS_PATH, 0, ad);
 
     /* MULTI_EXIT_DESC attribute - accept only if set in export filter */
-    a = bgp_find_attr(attrs0, BA_MULTI_EXIT_DISC);
-    if (a && !(a->type & EAF_FRESH))
-      bgp_unset_attr(&attrs, pool, BA_MULTI_EXIT_DISC);
+    /* Preserve MED to/from eBGP peers if preserve_med flag is set */
+    if (!p->cf->preserve_med)
+    {
+      a = bgp_find_attr(attrs0, BA_MULTI_EXIT_DISC);
+      if (a && !(a->type & EAF_FRESH))
+        bgp_unset_attr(&attrs, pool, BA_MULTI_EXIT_DISC);
+    }
   }
 
   /* NEXT_HOP attribute - delegated to AF-specific hook */
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h
index 455f04f9..07b1abbf 100644
--- a/proto/bgp/bgp.h
+++ b/proto/bgp/bgp.h
@@ -109,6 +109,7 @@ struct bgp_config {
   int allow_local_pref;			/* Allow LOCAL_PREF in EBGP sessions */
   int allow_as_sets;			/* Allow AS_SETs in incoming AS_PATHs */
   int enforce_first_as;			/* Enable check for neighbor AS as first AS in AS_PATH */
+  int preserve_med;			/* Preserve MED to/from eBGP peers */
   int gr_mode;				/* Graceful restart mode (BGP_GR_*) */
   int llgr_mode;			/* Long-lived graceful restart mode (BGP_LLGR_*) */
   int setkey;				/* Set MD5 password to system SA/SP database */
diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y
index 7279560b..796eb278 100644
--- a/proto/bgp/config.Y
+++ b/proto/bgp/config.Y
@@ -31,7 +31,7 @@ CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
 	STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST, FLOW4, FLOW6, LONG,
 	LIVED, STALE, IMPORT, IBGP, EBGP, MANDATORY, INTERNAL, EXTERNAL, SETS,
 	DYNAMIC, RANGE, NAME, DIGITS, BGP_AIGP, AIGP, ORIGINATE, COST, ENFORCE,
-	FIRST)
+	FIRST, PRESERVE)
 
 %type <i> bgp_nh
 %type <i32> bgp_afi
@@ -73,6 +73,7 @@ bgp_proto_start: proto_start BGP {
      BGP_CFG->setkey = 1;
      BGP_CFG->dynamic_name = "dynbgp";
      BGP_CFG->check_link = -1;
+     BGP_CFG->preserve_med = 0;
    }
  ;
 
@@ -182,6 +183,7 @@ bgp_proto:
  | bgp_proto ALLOW LOCAL AS expr ';' { BGP_CFG->allow_local_as = $5; }
  | bgp_proto ALLOW BGP_LOCAL_PREF bool ';' { BGP_CFG->allow_local_pref = $4; }
  | bgp_proto ALLOW AS SETS bool ';' { BGP_CFG->allow_as_sets = $5; }
+ | bgp_proto PRESERVE MED bool ';' { BGP_CFG->preserve_med = $4; }
  | bgp_proto GRACEFUL RESTART bool ';' { BGP_CFG->gr_mode = $4; }
  | bgp_proto GRACEFUL RESTART AWARE ';' { BGP_CFG->gr_mode = BGP_GR_AWARE; }
  | bgp_proto GRACEFUL RESTART TIME expr ';' { BGP_CFG->gr_time = $5; }
